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

how to determine a week?

Status
Not open for further replies.

dnstapes

Programmer
Jul 17, 2001
38
US
I'm making a form, and the user needs to be able to push a button and be able to see the start (Sunday) and end (Saturday) dates of the upcoming week. How do I get these values?

Thanks,
Dana
 

Dim curday As String, Nextsat As String
curday = Date
Do Until DatePart("w", curday, vbSunday) = 1 ' add days till sunday
curday = DateAdd("d", 1, curday)
Loop
Nextsat = DateAdd("d", 6, curday)

MsgBox "Next Sundays date = " & curday & vbCrLf & "Next saturday " & Nextsat
 
even small loops can be unnecessary

? DateAdd("d", vbSaturday - WeekDay(Now) + 1, Date)
7/29/01


(note that today is 7/26/01 on my computer)

I wouldn't make the poor overworked user do the mouse thing, just put the date(s) on the form during hte form activate event.

Of course, I only showed the Sunday Calculation (and even that could be simplified a bit) so you can use braindead2's suggestion for the following Saturday.

MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Why not make the above examples into a function?, you might find yourself using this in a query or report as well.

Andrew.
 
" ... make into a function ... "? It IS a function. An Intrinsic one. the porper name is "DateAdd". UDF's would normally consist of a bit more than the one liner.


MichaelRed
mred@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top