Click to See Complete Forum and Search --> : Dates


softweng
June 29th, 2001, 03:58 PM
If I have date like "6/29/01" how do I get the date for the first day of the week (Monday)
which in this case would be "6/25/01" using VB code.

Kris
Software Engineer
Phoenix,AZ

Harini
June 29th, 2001, 04:14 PM
Hello,

Weekday function returns the day of the week in numericals, i.e 1=Sunday.

Now using the Day function get the date i.e. 29. Now get the weekday of 6/29/01. Find the difference between 6/29/01 weekday and 2 (monday).
Subtract the difference from the day(6/29/01). That will be 4. Hence you will get the result as 6/25/01.

Thanks
Harini

vampyre
June 29th, 2001, 04:26 PM
Using the weekday function, you can get a number that represents the weekday of the entered date. You can then use several available date functions described in the MSDN library to subtract a number of days from the date and get the first day of the week.

mydate = date(Now) 'get the current date
myDay = Weekday(mydate) 'get the weekday from the date
mynewdate = date(myDate - myday) '(?)subtract the number of days to get the first day of this week.(?)



I don't really know if that last line will work, but the Weekday function should at least give you a chance to find out the day of the week. I hope this info was useful!

d.paulson
June 29th, 2001, 04:48 PM
Maybe this would work

Dim datetoday As Date
datetoday = Date
Text1 = DateAdd("d", -1 * (Weekday(datetoday) - 2), datetoday)


David Paulson

vampyre
June 29th, 2001, 05:22 PM
You're right: it works perfectly! Just convdert the Text1 to a date, and you have full functionality with the first day of the current week. Thank you, David!

softweng
July 2nd, 2001, 11:56 AM
That Works Great!!! Thanks So Much!!!

Kris
Software Engineer
Phoenix,AZ