By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
 435,396 Members | 2,501 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,396 IT Pros & Developers. It's quick & easy.

# DatePart function to display date for Monday and Friday of this week

 P: n/a I'm trying to use DatePart and Datediff functions to show the formatted m/dd/yyyy display for the dates of Monday and Friday of the current week. I want it to display as: Our Weekly Schedule 8/23/2004 thru 8/27/2004: Can't pinpoint the parameter to check for the current week. Is there a good reference anywhere to show how to use the methods and such of both datepart and datediff, or has anyone programmed something similar prior. Thanks in advance Chum Jul 19 '05 #1
Share this Question
3 Replies

 P: n/a Function GetWorkWeekDisplay() dtmDate = Date intDay = DatePart("w",dtmDate) If intDay < 2 Then dtmMonday = DateAdd("d",1,dtmDate) dtmFriday = DateAdd("d",6,dtmDate) Else dtmMonday = DateAdd("d",-(6-intDay),dtmDate) dtmFriday = DateAdd("d",6-intDay,dtmDate) End If GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday End Function dlbjr Pleading sagacious indoctrination! Jul 19 '05 #2

 P: n/a "dlbjr" wrote in message news:... Function GetWorkWeekDisplay() dtmDate = Date intDay = DatePart("w",dtmDate) If intDay < 2 Then dtmMonday = DateAdd("d",1,dtmDate) dtmFriday = DateAdd("d",6,dtmDate) Else dtmMonday = DateAdd("d",-(6-intDay),dtmDate) dtmFriday = DateAdd("d",6-intDay,dtmDate) End If GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday End Function dlbjr Pleading sagacious indoctrination! Thanks a ton, worked great! Jul 19 '05 #3

 P: n/a "dlbjr" wrote in message news:... Function GetWorkWeekDisplay() dtmDate = Date intDay = DatePart("w",dtmDate) If intDay < 2 Then dtmMonday = DateAdd("d",1,dtmDate) dtmFriday = DateAdd("d",6,dtmDate) Else dtmMonday = DateAdd("d",-(6-intDay),dtmDate) dtmFriday = DateAdd("d",6-intDay,dtmDate) End If GetWorkWeekDisplay = dtmMonday & " thru " & dtmFriday End Function dlbjr Pleading sagacious indoctrination! I revised the script somewhat to make sure it always displays monday's and friday's correct date for the current week: Function GetWorkWeekDisplay() dtmDate = Date intDay = DatePart("w",dtmDate) If intDay < 2 Then dtmMonday = DateAdd("d",1,dtmDate) dtmFriday = DateAdd("d",5,dtmDate) Elseif intDay = 2 Then dtmMonday = DateAdd("d",0,dtmDate) dtmFriday = DateAdd("d",4,dtmDate) Elseif intDay = 3 Then dtmMonday = DateAdd("d",-1,dtmDate) dtmFriday = DateAdd("d",3,dtmDate) Elseif intDay = 4 Then dtmMonday = DateAdd("d",-2,dtmDate) dtmFriday = DateAdd("d",2,dtmDate) Elseif intDay = 5 Then dtmMonday = DateAdd("d",-3,dtmDate) dtmFriday = DateAdd("d",1,dtmDate) Elseif intDay = 6 Then dtmMonday = DateAdd("d",-4,dtmDate) dtmFriday = DateAdd("d",0,dtmDate) Elseif intDay = 7 Then dtmMonday = DateAdd("d",-5,dtmDate) dtmFriday = DateAdd("d",-1,dtmDate) End If GetworkweekDisplay = dtmMonday & " thru " & dtmFriday End Function response.write "" & GetworkweekDisplay & "" Jul 19 '05 #4

### This discussion thread is closed

Replies have been disabled for this discussion.