Welcome to WebmasterWorld Guest from 54.161.217.24

Forum Moderators: open

Message Too Old, No Replies

Selecting Yesterday

     
11:46 pm on Feb 6, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 5, 2007
posts:107
votes: 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'");?

6:15 am on Feb 7, 2008 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member 5+ Year Member

joined:Nov 11, 2007
posts:774
votes: 3



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?

12:12 pm on Feb 9, 2008 (gmt 0)

Junior Member

5+ Year Member

joined:Dec 5, 2007
posts:107
votes: 0


Aha! That works great. Thanks.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members