homepage Welcome to WebmasterWorld Guest from 54.235.20.17
register, login, search, subscribe, help, library, PubCon, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library : Charter : Moderators: coopster & eelixduppy & jatar k

PHP Server Side Scripting Forum

    
sql date add query
Need to show records which are within or upto 21 days from date submitted.
ebanbury




msg:4324413
 3:32 am on Jun 10, 2011 (gmt 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.

 

Tommybs




msg:4324452
 7:13 am on Jun 10, 2011 (gmt 0)

Try
AND DATEDIFF(NOW(),add_date) < 21

rocknbil




msg:4324673
 5:06 pm on Jun 10, 2011 (gmt 0)

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

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
WebmasterWorld ® and PubCon ® are a Registered Trademarks of Pubcon Inc.
© Pubcon Inc. 1996-2012 all rights reserved