Per calcolare a quale settimana appartiene una data specifica, occorre impostare una specifica istruzione.
Prendendo ad esempio un campo data (Y.DTDYRQ) appartenente al nostro database, e impostare il valore calcolato in un campo (Y.WEDYRQ) entrambi appartenendo ad un file, as esempio (YGLS2APP Y) nella libreria XX, possiamo scrivere la seguente istruzione:
UPDATE
XX/YGLS2APP Y
SET Y.WEDYRQ = WEEK(SUBSTRING(DIGITS(Y.DTDYRQ), 1, 4) !! ‘-‘ !!
SUBSTRING(DIGITS(Y.DTDYRQ), 5, 2) !! ‘-‘ !!
SUBSTRING(DIGITS(Y.DTDYRQ), 7, 2) )
WHERE Y.DTDYRQ > 0
Di seguito trovate i dettagli dell’istruzione WEEK direttamente dal sito infocenter IBM
The WEEK function returns an integer between 1 and 54 that represents the week of the year. The week starts with Sunday, and January 1 is always in the first week.
http://www.ibm.com/support/knowledgecenter/ssw_ibm_i_71/db2/rbafzscaweek.htm?lang=it#d582397e63
>>-WEEK--(--expression--)--------------------------------------><
- expression
- An expression that returns a value of one of the following built-in data types: a date, a timestamp, a character string, or a graphic string.
If expression is a character or graphic string, it must not be a CLOB or DBCLOB, and its value must be a valid string representation of a date or timestamp.
The result of the function is a large integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.