---
url: >-
  /statelake/scripting-reference/functions-and-procedures/datetime-functions/endofaweek.md
---

# EndOfAWeek

The **EndOfAWeek** function returns a **TDateTime** date value that represents the last millisecond of a specified day of a specified week.

**EndOfAWeek** returns the last expressible moment of the day specified by **ADayOfWeek**, by replacing the time portion with 23:59:59.

* The **AYear** parameter specifies the year of the desired day.
* The **AWeekOfYear** parameter specifies the week of the year, where 1 is the first week in AYear that includes four or more days.
* The **ADayOfWeek** parameter indicates the desired day in the specified week, where 1 is Monday, 2 is Tuesday, e.t.c.

The definitions for **AWeekOfYear** and **ADayOfWeek** follow the ISO 8601 standard.

**Declaration**: Function EndOfAWeek(const AYear, AWeekOfYear, ADayOfWeek: Word): TDateTime;

An example follows.

```pascal
procedure OnMapEvent(var Value:Variant);
var
  TheDate : TDateTime;
  TheYear,TheWeek, TheDay : Word;
begin
 //Processing date is 29/11/2023, so the return value is 29/11/2023 23:59:59
  TheYear := 2023;
  TheWeek := 48;
  TheDay := 3;
  TheDate := EndOfAWeek(TheYear, TheWeek, TheDay);
  LogInfo('The end of the week date is '+FormatDateTime('dd/mm/yyyy hh:nn:ss',TheDate));
end;
```
