Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

sql date add query

Need to show records which are within or upto 21 days from date submitted.

3:32 am on Jun 10, 2011 (gmt 0)

New User

5+ Year Member

joined:June 10, 2011
posts: 1
votes: 0

Hi. I'm having a problem showing only the records which are 21 days or less from the date in which they are submitted.

This is my line of code at the end of a long sql query:

AND DATE_ADD(add_date, INTERVAL 21 DAY) <=current_date

However this is bringing up ONLY those records which are older than 21 days from the date submitted.

I need it to be the other way round, but don't know how to negate the code.

My Mysql database column is add_date and it is a datetime type.

Any help would be much appreciated.
7:13 am on June 10, 2011 (gmt 0)

Full Member

5+ Year Member

joined:June 21, 2007
posts: 316
votes: 0

AND DATEDIFF(NOW(),add_date) < 21
5:06 pm on June 10, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
votes: 0

I'd use date_sub instead. Same result, I think.

select * from table where add_date >= date_sub(now(), interval 21 day)

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members