Consultor Eletrônico



Kbase 18669: How to Calculate the Week Number of a Given Date
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   19/03/1999
How to Calculate the Week Number of a Given Date

Title: How to Calculate the Week Number of a Given Date

KnowledgeBase Number: 18669
Creation Date: 16-MAR-99
Modified Date:
This document applies to: Progress Versions 8.2A and Higher
Version and Release Number: 8.2A

Summary:

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.

Please note that this function is not compatible for European
calculations. Please see the weeknum.p sample program in the
$DLC/src/samples directory of your Progress installation that will
work for non U.S.A. countries.