Click to See Complete Forum and Search --> : Date Functions


Chris B.
February 21st, 2000, 08:12 AM
I am assigning the current date to a text box, however, I want to always subtract three days if the day falls on a "Monday". I have the days of the week all worked out, but I can't seem to subtract the amount of days that I need.

If (ResultDate = "Monday") then
MyTextBox.Text = Today - 3
End If



Of course the above does not work, but that is the basic problem I am having. If anyone has an idea please let me know.
Thanks

Lothar Haensler
February 21st, 2000, 08:18 AM
mytextbox.text = DateAdd("d", Now, -3)

February 21st, 2000, 08:43 AM
The function should actually be

Mydate = Format$(DateAdd("d", -3, Now), "dddd")



you can use format$ to format a date anyway you like check te help files.

Kyle Burns
February 21st, 2000, 09:07 AM
The WeekDay Function returns an integer representing the day of week referenced by a date.

dtMyDate = CDate(text1.Text) 'get date From Text Box
iDayOfWeek = WeekDay(dtMyDate) 'Ask for the day of week

If iDayOfWeek = 2 then 'If it's Monday
dtMyDate = dtMyDate - 3 'Subtract 3 days
text1.Text = Format(dtMyDate, "MM/DD/YYYY")
End If