Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > DatePart function to display date for Monday and Friday of this week

Reply
Thread Tools

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

 
 
Chumley the Walrus
Guest
Posts: n/a
 
      08-25-2004
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
 
Reply With Quote
 
 
 
 
dlbjr
Guest
Posts: n/a
 
      08-25-2004
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!


 
Reply With Quote
 
 
 
 
Chumley the Walrus
Guest
Posts: n/a
 
      08-26-2004
"dlbjr" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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!
 
Reply With Quote
 
Chumley the Walrus
Guest
Posts: n/a
 
      08-27-2004
"dlbjr" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> 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 "<font size = 3>" & GetworkweekDisplay & ""
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
datepart function =?Utf-8?B?QWFyYW43Ng==?= ASP .Net 2 11-03-2005 05:54 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP General 11 11-08-2003 11:24 PM
Given a date, how to find the beginning date and ending date of that week Matt ASP .Net 1 11-08-2003 09:14 PM
Given a date, how to find the beginning date and ending date of that week Matt C Programming 3 11-08-2003 09:07 PM
Given a date, how to find the beginning date and ending date of that week Matt C++ 2 11-08-2003 08:30 PM



Advertisments