PDA

View Full Version : Start/End Dates for a Week


Bullschmidt
10-14-2005, 06:46 AM
If I know the week number and the year, how can I calc the beginning and ending dates of the week?

For background I'm going to do some grouping by week but don't just want to call the weeks Week 25, Week 26, Week 27, etc. And the week number is to be calculated with:

DatePart("WW", [MyDateField])

felgall
10-15-2005, 12:05 AM
Different places around the world start the week on different days. Some places Saturday is the first day of the week, some places Monday is the first day, most places Sunday is.

Bullschmidt
10-15-2005, 12:23 AM
The American default of Sunday would be fine as it will be on an American server.

BaldEagle
10-15-2005, 04:18 AM
See if this will suit your needs:


'// FirstDate can be hardcoded or better yet stored in a db and updated once
'// a year, it should be the Date of the Sunday that starts the week for that
'// year
FirstDate = CDate("12/26/2004")

MyDate = Date()
WeekOfYear = DatePart("ww",MyDate) - 1
WoyFirstDate = DateAdd("ww",WeekOfYear,FirstDate)
WoyLastDate = DateAdd("d",6,WoyFirstDate)


You may need to tweak it a little as you see fit for your application.

I tested it on today's date (10/14/2005) and got This result:
WoyFirstDate = 10/9/2005
WoyLastDate = 10/15/2005

BaldEagle


[EDIT] Actually, I reckon you could just calculate the FirstDate of the current year by building a 1/1/(curent year) date and then use DateAdd to calc it.