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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Identifying week range by todays date

Status
Not open for further replies.

werosen1

Programmer
Mar 30, 2006
16
US
I'm trying to write an SQL query that identifies today's date, and then provides the date range for that date's week, so I can return all my database records that fall in that week's date range.

Is there a way to do this?

Regards
 
unfortunately, date arithmetic is probably the one area where ANSI SQL is least implemented in the various database systems, so how to do it will likely depend on which one you're using

please re-post your question in the appropriate forum



r937.com | rudy.ca
 
ANSI SQL compliant solution:

Code:
SELECT * FROM sometable
WHERE datcol BETWEEN (current_date - CAST(dayofweek(current_date)-1 AS interval day))
             AND     (current_date + CAST(7-dayofweek(current_date) AS interval day))
 
Sorry about that, of course DAYOFWEEK is *not* an ANSI SQL function.

Don't know what I was thinking...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top