DoW(), Week()

Returns the numeric values of the day of the week and week of the year, based on the date or datetime supplied. You can optionally specify a starting point as well.
Usage
nDayOfWeek = DOW( dDate | tDateTime [, nFirstDayofWeek ] )
nWeekOfYear = WEEK( dDate | tDateTime [, nFirstWeek ] 
                    [, nFirstDayOfWeek ] )

Parameter

Value

Meaning

dDate | tDateTime

Date or DateTime

The date or datetime value from which to calculate the day of the week or week of the year.

nFirstDayofWeek

Omitted

Use Sunday as the first day. This is for compatibility with older versions of FoxPro.

0

Use the current setting of FDOW.

1 - 7

Use days Sunday - Saturday as the first day.

nFirstWeek

Omitted or 1

The first week includes January 1.

0

Use the current setting of FWEEK.

2

The first week of the new year has four or more days.

3

The first week of the new year falls entirely within the new year.

nDayOfWeek

1 - 7

Indicates which day of the week dDate | tDateTime is.

nWeekOfYear

1 - 53

Indicates which week of the year dDate | tDateTime is.


These functions return the day and week for the supplied date or datetime. The parameters nFirstDayOfWeek and nFirstWeek can be confusing if you haven't worked with them before, and can give less than intuitive results.Let's try an example to see if your confusion can lead to total befuddlement, er, enlightenment. January 1, 1998 was a Thursday, and your client tells you that they never start a new workweek with two or fewer days, so Thursday and Friday count as the last week of 1997. The WEEK() function, with a parameter of 2, gives you a return value of 53, for the 53rd week of 1997, for January 1st and 2nd.
? WEEK({^1998-01-01},2) && returns 53, the last week of 1997
On the other hand, if your client tells you they always start the new year on a full seven-day week (a good idea if they track production per week), you could use the parameter of 3 so that January 1st and 2nd fall into the 52nd full week of 1997.
? WEEK({^1998-01-01},3)  && returns 52, the 52nd and last full 
                         && 7-day week of 1997
If your client's company starts their weeks on Monday, or Thursday, or Saturday, you can adjust that, too, with the nFirstDayofWeek parameter.

Figure 1: The Regional tab of the Tools-Options dialog includes First Day of Week and First Week of Year.

It is possible to set the "first day of week" and "first week of year" settings on the Tools-Options dialog, under the Regional tab (see Figure 1), but the settings you make apply only to the development version—runtime versions do not check the Options stored in the Registration Database. For runtime situations, you might want to set these in the Config.FPW file with FDOW= and FWEEK=, or programmatically with the equivalent SET FDOW TO and SET FWEEK TO. However, for those folks really into spelunking the depths and messing with what Microsoft has handed us, check out the Registration Database to see where all the native settings are stored. Search for the key:
MyComputer\HKEY_CURRENT_USER\Software\Microsoft\VisualFoxPro\<VFP version>\Options

Example

? DOW({^1982/4/11})   && returns 1, since 4/11/82 was a Sunday
? DOW({^1982 4 11},2) && returns 7, the week starts on Monday
? WEEK({^2001.01.01}) && returns 1, the first week 
                      && of the new millennium

See Also

Date(), Day(), DMY(), GoMonth(), MDY(), Month(), Registration Database, Set Century, Set Date, Set FDoW, Set FWeek, Set Mark To, Year()


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .