Consultor Eletrônico



Kbase P15902: How to Calculate the Week Number of a Given Date - American calculation
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/16/2008
Status: Unverified

GOAL:

How to Calculate the Week Number of a Given Date - American calculation

FIX:

The following user defined function will return the week number (from 1 to 52) that a given date falls into:

FUNCTION WeekNumber RETURNS INTEGER (INPUT dSomeDate AS DATE):

DEFINE VARIABLE dStart AS DATE NO-UNDO.

ASSIGN dStart = DATE(1,1,YEAR(dSomeDate))
dStart = dStart + (8 - WEEKDAY(dStart)).

IF dStart > dSomeDate THEN
RETURN 1.
ELSE
RETURN 2 + INTEGER(TRUNC(INTEGER(dSomeDate - dStart) / 7,0).

END FUNCTION.