Welcome to WebmasterWorld Guest from 54.167.153.63

Forum Moderators: open

Message Too Old, No Replies

Selecting Yesterday

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

5+ Year Member



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)

WebmasterWorld Senior Member 5+ Year Member




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)

5+ Year Member



Aha! That works great. Thanks.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month