Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dates From Last Week?

Status
Not open for further replies.

junkjones

Programmer
Jul 14, 2000
52
GB
I have a query where I need to find out information from the past week. It looks something like this:

lastmonday = "08-04-2003"
lastsunday = "08-10-2003"

SQL = "select * from table where (dateran BETWEEN lastmonday and lastsunday)"

This part works, but I'm having troubles figuring out how to get a value for 'lastmonday' and 'lastsunday'. It's easy to do a date subtract and take off a certain amount of days, but the amount to subtract would be different depending on what day it is. Any suggestions?
 
today = date()

lastMonday = dateAdd("d",-1 * (datePart("w",today)-2),today)
lastSunday = lastMonday + 6


Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Oh, btw, you may want to use Now instead of today, think today is not valid in VBScript.

Here's my monday of last week script:
Code:
lastWkMon = DateAdd("d",-1 * (WeekDay(Now) + 5),Now)
Pretty similar except I had a differant interpretation of which week we wanted monday from.

[sub]01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111[/sub]
minilogo.gif alt=tiernok.com
The never-completed website
 
tarwyn - didn't use today, I used date() which is the same as now() without time of day info....

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
Sorry, tired from overworking myself this week :p
I saw that tyhe first time around but missed it the second time...
 
and if you wanted to find the dates directly in sql server (say in a stored procedure) I did basically the same thing in this thread:
thread183-619930

I'm a bit leery of VBscript & dates.. very easy to be thrown off by regional settings on your (ASP) server :(

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top