Newbie question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I'm learning MySQL, and I am struggling with a few odds and ends. The one
that I can't see how to crack is to search by age.

The records in my database have a datetime field for when they were

In my web front end I want to do a "show me entries inserted during the last
[1-9] Days or [1-3] months"

I am guessing the query will be something like

Select * where Date > NOW () - <some number of days or months>

My PHP script can take account for if it is filtering in days or months, but
I cant work out the actual syntax for subtracting a set number of days or
months from NOW()

Any help gratefully accepted!



Re: Newbie question

Chris Styles wrote:
Quoted text here. Click to load it

SELECT * FROM `tablename` WHERE `datecol` > NOW() - INTERVAL 9 DAY


SELECT * FROM `tablename` WHERE `datecol` > DATE_SUB(NOW(), INTERVAL 9 DAY)


Bill K.

Site Timeline