Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Given a date, how to find the beginning date and ending date of that week

Reply
Thread Tools

Given a date, how to find the beginning date and ending date of that week

 
 
Matt
Guest
Posts: n/a
 
      11-08-2003
My ASP page allows the user select the date, and it will display the report
during that week of that date.

My question is when the program query database, I need to know the beginning
date and ending date of that week.

Any ideas??


 
Reply With Quote
 
 
 
 
Rob Meade
Guest
Posts: n/a
 
      11-08-2003
"Matt" wrote...

> My question is when the program query database, I need to know the

beginning
> date and ending date of that week.


<%
' strDate = RS("Date")
strDate = Date()

strWeekdayName = LCase(WeekdayName(weekday(strDate)))

Dim myDaysArray(7)

myDaysArray(0) = "monday"
myDaysArray(1) = "tuesday"
myDaysArray(2) = "wednesday"
myDaysArray(3) = "thursday"
myDaysArray(4) = "friday"
myDaysArray(5) = "saturday"
myDaysArray(6) = "sunday"

For intLoop = 0 To UBound(myDaysArray)

If strWeekdayName = myDaysArray(intLoop) Then

If intLoop = 0 Then

strStartOfWeekDate = strDate
strEndOfWeekDate = DateAdd("d", 6, strDate)

ElseIf intLoop = 6 Then

strStartOfWeekDate = DateAdd("d", -6, strDate)
strEndOfWeekDate = strDate

Else

strStartOfWeekDate = DateAdd("d", -intLoop , strDate)
strEndOfWeekDate = DateAdd("d", (6-intLoop), strDate)

End If

End If

Next

Response.Write "Current Date : " & strDate & "<br>"
Response.Write "Start Of Week Date : " & strStartOfWeekDate & "<br>"
Response.Write "End Of Week Date : " & strEndOfWeekDate & "<br>"
%>

If your 'week' doesn't start on a Monday, change the values in the array, ie
:

tueday
wednesday
thursday
friday
saturday
sunday
monday

Hope this helps, oh and if you run it as it is at the moment it should work
fine, commented line at the top for your date from the database etc, then
just remove the response.writes at the bottom.

Regards

Rob


 
Reply With Quote
 
 
 
 
Bob Barrows
Guest
Posts: n/a
 
      11-08-2003
Matt wrote:
> My ASP page allows the user select the date, and it will display the
> report during that week of that date.
>
> My question is when the program query database, I need to know the
> beginning date and ending date of that week.
>
> Any ideas??



Don't you think the type and version of database you are using might be
relevant information (it is)?

Do you want to calculate these dates in the vbscript code? or in the
database query?

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      11-08-2003
"Bob Barrows" wrote ...

> Don't you think the type and version of database you are using might be
> relevant information (it is)?
>
> Do you want to calculate these dates in the vbscript code? or in the
> database query?


Arrghh!! You're going to post up a 2 line SQL statement now Bob aren't you
that will do exactly what Matt wants and will make me look bad ;o)

Rob


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      11-08-2003
Rob Meade wrote:
> "Bob Barrows" wrote ...
>
>> Don't you think the type and version of database you are using might
>> be relevant information (it is)?
>>
>> Do you want to calculate these dates in the vbscript code? or in the
>> database query?

>
> Arrghh!! You're going to post up a 2 line SQL statement now Bob
> aren't you that will do exactly what Matt wants and will make me look
> bad ;o)
>
> Rob



It depends on what his database is ...

Bob

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      11-08-2003
"Bob Barrows" wrote ...

>
> It depends on what his database is ...


I know some of the Weekday stuff I've done in the code above can be done in
the SQL statement in SQL Server, any better suggestions for the ASP version
which I did above?

I dont often put forward a code block for people in the group as I'm often
concerned I'll do it in about 100 lines when 10 would have worked

Rob


 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      11-08-2003
Rob Meade wrote:
> "Bob Barrows" wrote ...
>
>>
>> It depends on what his database is ...

>
> I know some of the Weekday stuff I've done in the code above can be
> done in the SQL statement in SQL Server, any better suggestions for
> the ASP version which I did above?
>
> I dont often put forward a code block for people in the group as I'm
> often concerned I'll do it in about 100 lines when 10 would have
> worked
>
> Rob


Are you sure you want me to answer that?

dim dToday, dWkStartDate, dWkEndDate
dToday = Date()
'assuming Sunday is first day of week:
dWkStartDate = dToday
Do until weekday(dWkStartDate) = vbSunday
dWkStartDate = DateAdd("d",-1,dWkStartDate)
Loop
dWkEndDate = DateAdd("d",6,dWkStartDate)

Bob Barrows


MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      11-08-2003
"Bob Barrows" wrote ...

> Are you sure you want me to answer that?
>
> dim dToday, dWkStartDate, dWkEndDate
> dToday = Date()
> 'assuming Sunday is first day of week:
> dWkStartDate = dToday
> Do until weekday(dWkStartDate) = vbSunday
> dWkStartDate = DateAdd("d",-1,dWkStartDate)
> Loop
> dWkEndDate = DateAdd("d",6,dWkStartDate)



grrrrr.....

hehe - as I suspected - all over in half a dozen lines of code...bah...last
time I make a suggestion! )

Rob


 
Reply With Quote
 
dlbjr
Guest
Posts: n/a
 
      11-08-2003
dtmDate = "10/12/03"
dtmStartOfWeek = DateAdd("d",-(DatePart("w",dtmDate) - 1),dtmDate)
dtmEndOfWeek = DateAdd("d",7 - DatePart("w",dtmDate),dtmDate)

-dlbjr

Discerning resolutions for the alms


 
Reply With Quote
 
Rob Meade
Guest
Posts: n/a
 
      11-08-2003
...and now were down to 3 lines of code... D

Any advances on 3....come on - someone must be able to do it ....

Rob


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 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
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57