Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WEEK() function
Message
 
To
20/05/2002 09:31:39
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00658841
Message ID:
00659304
Views:
23
Jonathan,
>
>I have the week number during the year.
>Is there any way I can find what date was it.
>

I do employ a few small functions for that as
there is no built in as far as I know. Depending
on the Week-Settings (what is the first day
of the week and what is called the first week
of the year see documentation to week()) You will
have different results concerning the first week
of a year. The first of January might be in the
52nd Week of the year before or the first week of
the actual year.

What we did is calculate the date of the first
week of the year and from there calculate the date
of the first day of the week in question.

We in Germany start our weeks with Monday and
the first week is the week that contains four days
or more. So the two parameters of Week() are 2 and 2.

The following function is put together for You so
it might not run as it is but maybe it helps You
to get the drift.
*=========================================================
*
*         FUNCTION: Week2Date             
*
*=========================================================
FUNCTION Week2Date             
*  Created...........:  21.Mai 2002, 14:29 Uhr
*  Changed...........:   
*  Description.......:  Return the Date for the first 
*                        day of a given week-no
*  Calling Samples...:  ? Week2Date(<ExpN1>[, <ExpN2>])
*  Parameters........:  tn_Week, tn_Year
*  Returns...........:  Date
lparameters    tn_Week, tn_Year
LOCAL ld_YearStart, ld_WeekStart

tn_Week = iif(vartype(tn_Week) = "N", tn_Week, 1)
tn_Year = iif(vartype(tn_Year) = "N", tn_Year, year(date()))

#define cn_WeekStart      2  && The first week starts
                             && with the first four-day-week
#define cn_FirstDayOfWeek 2  && Monday is the first 
                             && day of the week


*====================================*
*  First we get the day that starts  *
*  the first week of the year.       *
*  Thus lets go back a few days into *
*  the year before                   *
*====================================*
ld_YearStart = date(tn_Year, 1, 1) -5

do while .T.
    if week(ld_YearStart, cn_WeekStart, cn_FirstDayOfWeek) = 1
        *===============================================*
        *  Yes, the first week of the Year starts here  *
        *===============================================*
        exit
    else
        ld_YearStart = ld_YearStart + 1                
    endif
enddo


*===================================*
*  OK, Now we have the Date that    *
*  represents the first day of the  *
*  year's first week. From that we  *
*  should be able to easily         *
*  calcualte the date of the week   *
*  provided                         *
*===================================*

ld_WeekStart = ld_YearStart + ((tn_Week-1)*7)

return ld_WeekStart
*-- eof Week2Date
Hope this works for You
Regards from Berlin

Frank

Dietrich Datentechnik (Berlin)
Softwarekombinat Teltow (Teltow)

Frank.Dietrich@dd-tech.de
DFPUG # 327
Previous
Reply
Map
View

Click here to load this message in the networking platform