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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Kind of strange thing going on with DOW() and SET FDOW 3

Status
Not open for further replies.
Feb 14, 2000
425
US
Kind of strange thing going on

I have never really needed to mess around much with DOW() it always pretty much worked for me as is and I use it very often. However, I have run into a situation where I need to change from a Sunday through Saturday calendar period to a Monday through Sunday period. I was excited to use something new. So I SET FDOW 2 and tested on today 11/09/2023 (a Thursday) and the result was 5 not the expected 4. I then tested the same date but using DOW({11/09/2023},2) and got the correct result of 4. Am I missing something here or is there some issue with SET FDOW I am not seeing?

I would need to review many lines of code if I need to modify any DOW() functions used where SET FDOW would handle throughout with 1 line.

Steve Bowman
Independent Technology, Inc.
CA, USA
 
Indeed it should work as you expect it, setting FDOW changes what day is used as start day of a week.

But, for DOW() to take FDOW into account you have to call it with DOW(Datevalue,0).

So you can only keep code running unchanged, if you would have used the 0 paramter always. Instead you used the default, which is alwayss using Sunday as start of the week, no matter if you change FDOW or not.

PS: The help of DOW says it this way for nStartoFweek 0:
help said:
DOW( ) uses whatever day is currently selected in the Week Starts On list box, which appears on the Regional Tab in the Options dialog box.
If you set FDOW you do change what is displayed as "Week Starts On", so that's not directly describing that dependency, but it works that way.

So unfortunately you don't get around changing all DOW() calls to either DOW(...,2) to work for Monday, or - better for future required changes, perhaps - change it to DOW(...,0) and make the FDOW setting. By the way, it works as the Windows regional setting is, if you SET SYSFORMATS ON, because then FDOW besides other VFP settings are influenced by Windows (regional) system settings.

Take it with a pinch of salt, though. SET SYSFORMATS ON actually only has the effect to change all VFP environment setting to Windows settings exactly at that moment, when you switch from OFF to ON. If you change individual setting to something else that overrides the system settings for VFP and you never influence the system settings themselves, which are often not under control of users but limited to administtrative access. That speaks for overriding whatever is necessary yourself and making that configurable. And then, regarding start of the week, it becomes a matter of taste if you let users define the FDOW and use it in your DOW() calls directly or SET FDOW and use it indirectly with DOW(x,0). Anyway, as so often, code can only be adaptive, if you think of that from the outset. Many VFP defaults are Amercian, not international.

Chriss
 
Got it, thank you for the simple answer. That does sort of make sense why it works that way. Every day is a school day!

Steve Bowman
Independent Technology, Inc.
CA, USA
 
Hi Steve,

I always use DOW with the SET FDOW:

? DOW(dDATE, SET("FDOW")).

Then you won't be surprised by the results.

hth

MarK
 
Treue, Mark, that also works, because that's what 0 does, indirectly, but with less VFP code. So DOW(dDATE, SET("FDOW")) is always teh same as DOW(dDATE, 0)

Chriss
 
Hi Chris,

You're right - I overlooked it in the help file

MarK
 
Very interesting. I work with lots of various payroll, accounting, and delivery service software and reporting so DOW() is sprinkled all over. I just found myself thinking about how I could whip up a utility for that and thanks to you I do not have to.


Steve Bowman
Independent Technology, Inc.
CA, USA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top