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

Find nearest day of week

Status
Not open for further replies.

mikeopolo

Technical User
May 25, 2003
54
NZ
I'm developing a routine to group sales transactions by week numbers, and then group those into reporting months on qa 4-4-5 basis.

1st problem: given a date value, how would I find the nearest Saturday?

so:

ldDate1 = ctod("31/03/2008")
ldSaturday = ?????

Regards
Mike
 
Assuming Saturday is DOW() = 7 then next Saturday would be:

Code:
SET DATE DMY
ldDate1 = CTOD("31/3/2008")
ldSaturday = ldDate1 + 7 - DOW(ldDate1)
 
Assuming Saturday is DOW() = 7 ....

And, if Saturday isn't day 7 (perhaps because the user has set something different in Control Panel), a small mod to TheRambler's code will fix it:

Code:
ldSaturday = ldDate1 + 7 - DOW(ldDate1[b],1[/b])

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Nearest Saturday could precede the date.
Question does not specify NEXT Saturday
 
cricket - add:

Code:
IF ldSaturday - ldDate1 > 3
  ldSaturday = ldSaturday -7
ENDIF
 
Thank you to all four contributors, that's the solution I require!

Regards
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top