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

Query by dates to find history records

Status
Not open for further replies.

JMay0816

Programmer
Mar 1, 2007
34
0
0
US
what is the correct way to query on a date field in a table to pull a value that is older than 3 days?

Date field format is 2007-04-04

I only want records where the date is 2007-04-01 or earlier.

thx
 
To select stuff more than 3 days old use curdate() to return the current date then use the Interval function for your offset :

Code:
SELECT *
FROM mytable
WHERE mydatefield > ( curdate( ) - INTERVAL 3 DAY )


___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
John, you want < and not > your query will return records from three days ago and newer. The OP wanted items from three days ago and older.

Yours will return records from 2007-04-12 but they want records from 2007-03-29 for instance.
 
Thanks guelphdad - excuse my thick finger syndrome!

___________________________________________________________
If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
Steam Engine Prints
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top