Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Week() does not return the correct value

Status
Not open for further replies.

mirkado227

Programmer
May 28, 2005
12
TR
Code:
SET FDOW TO 2  && week starts with monday
SET FWEEK TO 1 && The first week contains January 1st

? WEEK({31.12.2006})     && returns 1 but should return 53
? WEEK({31.12.2006},1)   && returns 1 but should return 53
? WEEK({31.12.2006},1,2) && returns 53

It seems, that the set instructions (FDOW and FWEEK) has no effect. Do I make an error in reasoning?
 
With 31.12.2005 I got another strange result:

Code:
SET FDOW TO 2  && week starts with monday
SET FWEEK TO 1 && The first week contains January 1st

? WEEK({31.12.2005})     && returns 53 (correct)
? WEEK({31.12.2005},1)   && returns 53 (correct)
? WEEK({31.12.2005},1,2) && returns 1  (incorrect)
 
? WEEK({31.12.2005},1,2) && returns 1 (incorrect)

Why would you say this is wrong? Your code is asking "what is the week number that contains January first (first parameter) and starts on a monday (second parameter)".

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Hi Mike

Yes, you are right. I interpreted the week-funktion with this parameteres wrong.
But: there cannot be a 53th week of a year. Is this correct?

 
An often overseen fact is, the settings for FDOW and FWEEK only take effect, if you pass 0 as the corresponding parameters in eg the WEEK() function (see help on WEEK, DOW, etc.):

Code:
SET FDOW TO 2  && week starts with monday
SET FWEEK TO 1 && The first week contains January 1st

? DOW({^2005-12-31},0) && returns 6 = saturday (respects FDOW=2!)
? DOW({^2005-12-31}) && returns 7 = saturday (because FDOW = 1 = sunday is assumed!)

* so 1st January 2006 is sunday and so week 1 of 2006 goes 
* from monday, 26th December 2005 to sunday, 1st January 2006.

* these three calls are equal now with FDOW=2 and FWEEK=1:
? WEEK({^2005-12-31},0,0) && returns 1 (correct)
? WEEK({^2005-12-31},1,0) && returns 1 (correct)
? WEEK({^2005-12-31},1,2) && returns 1 (correct)

If you omit 0 as parameter, foxpro will use standard values of 1 as FDOW and 1 as FWEEK, not what you set with SET FDOW and SET FWEEK! So in your case your first 2 calls really had other parameters (both 1) than the last full call (with parameters 1,2).

With January 1st being part of week 1 - week 1 will mostly begin in the previous year, so you seldom (or never?) have a 53rd week. Standard of german calendars on the other side is is FDOW 2 and FWEEK 2. Especially with this setting of FWEEK, there can rather often be a 53rd week.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top