homepage Welcome to WebmasterWorld Guest from 54.161.220.160
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

    
Selecting Yesterday
itledi

5+ Year Member



 
Msg#: 3568092 posted 11:46 pm on Feb 6, 2008 (gmt 0)

Hello,

I am using MySQL in a PHP environment.

In a MySQL query I would like to limit my search to just results published today.

mysql_query("SELECT * FROM table WHERE published>='".date("Y-m-d")." 00:00:00'");

That works great.

But how would I go about selecting dates published just yesterday?

mysql_query("SELECT * FROM table WHERE published>='YESTERDAY()' AND published<'".date("Y-m-d")." 00:00:00'");?

 

ZydoSEO

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3568092 posted 6:15 am on Feb 7, 2008 (gmt 0)


Did you try

SELECT * FROM table
WHERE published >= CURDATE()

for items published today and

SELECT * FROM table
WHERE published >= DATE_SUB(CURDATE(), INTERVAL 1 DAY) AND published < CURDATE()

for yesterday?

itledi

5+ Year Member



 
Msg#: 3568092 posted 12:12 pm on Feb 9, 2008 (gmt 0)

Aha! That works great. Thanks.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved