HYYWD: Returning the Year and Week Number From a Date-Time Value

How to:

The week number returned by HNAME and HPART can actually be in the year preceding or following the input date.

The HYYWD function returns both the year and the week number from a given date-time value.

The output is edited to conform to the ISO standard format for dates with week numbers, yyyy-Www-d.


Top of page

x
Syntax: How to Return the Year and Week Number From a Date-Time Value
HYYWD(dtvalue, output)

where:

dtvalue

Date-time

Is the date-time value to be edited.

output

Alphanumeric

The output format must be at least 10 characters long. The output is in the following format:

yyyy-Www-d

where:

yyyy

Is the four-digit year.

ww

Is the two-digit week number (01 to 53).

d

Is the single-digit day of the week (1 to 7). The d value is relative to the current WEEKFIRST setting. If WEEKFIRST is 2 or ISO2 (Monday), then Monday is represented in the output as 1, Tuesday as 2.

Using the EDIT function, you can extract the individual subfields from this output.



Example: Returning the Year and Week Number From a Date-time Value

The following converts the TRANSDATE date-time value to the ISO standard format for dates with week numbers. WEEKFIRST is set to ISO2, which produces ISO standard week numbering:

 ISODATE/A10 = HYYWD(TRANSDATE, 'A10');     

For date component 1999/01/30 04:16, the value is 1999-W04-6.

For date component 1999/12/15, the value is 1999-W50-3.


iWay Software