F_GetWeekOfTheYear

You can use this function to obtain the week of the year represented by a specified date and time value. The function uses the ISO 8601 standard definition of a week.
- The first week of a year is defined as the first week with four or more days in that year (DIN 1355 / ISO 8601);
- A week is considered to start an a Monday and end on Sunday.
- The returned value is between 1 and 53. The first week of a year has the number 1;
- If the first calendar day of the year is a Friday, Saturday, or Sunday, then for the first three, two, or one days of the calendar year, the F_GetWeekOfTheYear returns the last week of the previous year;
- If the last calendar day of the year is a Monday, Tuesday, or Wednesday, then for the last one, two, or three days of the calendar year, F_WeekOfTheYear returns 1 (the first week of the next calendar year);
FUNCTION F_GetWeekOfTheYear : WORD
VAR_INPUT
VAR_INPUT
in : DT;
END_VAR
in: Specified date and time value.
Example in structured text:
PROGRAM MAIN
VAR
dtNow : DT := DT#2008-03-17-12:00;
weekOfYear : WORD;
END_VAR
weekOfYear := F_GetWeekOfTheYear(dtNow);
The result is: 12.
Requirements
Development environment | Target system type | PLC libraries to be linked |
---|---|---|
TwinCAT v2.10.0 Build >= 1325 | PC or CX (x86, ARM | TcUtilities.Lib |