Click to See Complete Forum and Search --> : ASP - DatePart() Query


malice
September 29th, 2005, 04:40 PM
First of all apologies if this is in the wrong forum!

I am developing an Access datebase which communicates with an ASP script. It is basically a booking system. The user makes a booking on a particular day and what I am having trouble doing is generating date for bookings made on particular days of the week e.g. Monday Bookings, Tuesday Bookings etc.

I am using the DatePart function to return a number corresponding to the day of the week that the booking was made. I want the booking week to run from Monday to Sunday. The MSDN help on DatePart() tells me that to do this I need to pass a 2 as a function parameter.

The syntax is as follows:
.........
recDate = recordSet("bkDate").Value

' 2 => first day of week = monday
dayOfWeek = DatePart("w", recDate, 2)

.........

dayOfWeek should now contain a number from 1 to 7 telling me the day of the week but what I actually get is a number from 1 to 6 (Monday to Saturday). In other words, Sunday doesn't appear!!

I'm wondering if this is supposed to be the case and if so, how do I get ASP to give me a week from Monday to Sunday?

olivthill
September 29th, 2005, 05:11 PM
I have tested the following program, and it is working fine.
date_plus1 = DateAdd("d", 1, Date)
date_plus2 = DateAdd("d", 2, Date)
date_plus3 = DateAdd("d", 3, Date)
date_plus4 = DateAdd("d", 4, Date)
date_plus5 = DateAdd("d", 5, Date)
date_plus6 = DateAdd("d", 6, Date)
date_plus7 = DateAdd("d", 7, Date)
Wscript.Echo "Weekday0: " & Date & " --> " & DatePart("w" , Date)
Wscript.Echo "Weekday1: " & Date_plus1 & " --> " & DatePart("w" , Date_plus1)
Wscript.Echo "Weekday2: " & Date_plus2 & " --> " & DatePart("w" , Date_plus2)
Wscript.Echo "Weekday3: " & Date_plus3 & " --> " & DatePart("w" , Date_plus3)
Wscript.Echo "Weekday4: " & Date_plus4 & " --> " & DatePart("w" , Date_plus4)
Wscript.Echo "Weekday5: " & Date_plus5 & " --> " & DatePart("w" , Date_plus5)
Wscript.Echo "Weekday6: " & Date_plus6 & " --> " & DatePart("w" , Date_plus6)
Wscript.Echo "Weekday7: " & Date_plus7 & " --> " & DatePart("w" , Date_plus7)

malice
September 30th, 2005, 11:31 AM
Ahh, thanks Olivthill! I never thought about using the DatePart() function. I guess what I will try and do is treat Monday as the first day of the week and use DatePart() to derive the rest of the days from that.

Thanks for your help!