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

extracting date

Status
Not open for further replies.

KryptoS

Programmer
Joined
Feb 7, 2001
Messages
240
Location
BE
in my table I have a field with a date. Now I only want to get the records fromt the last 7 days :

$sql = ("SELECT * FROM tbl_images WHERE datum > datesub(now(),7)");

but I think mysql doesn't know what datesub is... is it possible to do with a php syntax?

The One And Only KryptoS
 
Damn, you search 2 hours for this and then you finally post your question on tek-tips and then 2 minutes later you find the solution...

$sql = ("SELECT * FROM tbl_images WHERE datum > subdate(NOW(),Interval 7 day)");

The One And Only KryptoS
 
I think MySQL knows what DATE_SUB is. This should work:
Code:
SELECT * FROM tbl_images
WHERE datum > DATE_SUB ( NOW(), INTERVAL 7 DAY )

Andrew
Hampshire, UK
 
DATE_SUB also takes month and year as arguments :-)

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top