Click to See Complete Forum and Search --> : Date of the first day of a week


visual fzz
January 17th, 2000, 04:22 AM
Hi everybody

I want to know the date of the first day of a week.
Example: I choose a date : the 5th of MAY 2003.
I can have the week (between 1 and 52)
But I want the date of the first day of this week.
I can get the day (monday, tuesday...) and if I know how many days there are in the month I can move backward until the first day.
Is there a method faster and easier than this one???

Fzz

J B
January 17th, 2000, 04:52 AM
you need to deduct the day of the week from the date and this gives you the first day of the week for that date.

try this
[vbcode
Dim lDay As Long
If IsDate(Text1.Text) Then
Text2.Text = (CDate(Text1.Text)) - (Weekday(Text1.Text) - 1)
End If

[/vbcode]

hope it helps

jonathan

Clearcode
January 17th, 2000, 04:54 AM
assuming date is in a variable "dtIn" then:

DATEadd("d",0-((datepart("w",dtIn))-1), dtIn)



is about as short as I can get it.

HTH,
Duncan

Dr_Michael
January 17th, 2000, 06:22 AM
If you use DTPicker control for the input of the date value, then check out the property "DayOfWeek". Maybe this helps.


Michael Vlastos
Automation Engineer
Company SouthGate Hellas SA
Development Department
Athens, Greece