Nexy Posted June 21, 2008 Share Posted June 21, 2008 Hello, jut wondering how do I select everything in a table that has today's date only? For example: "SELECT * FROM table WHERE date = today() ORDER BY id DESC"; Something like that. Thank You! Quote Link to comment Share on other sites More sharing options...
webent Posted June 21, 2008 Share Posted June 21, 2008 Assuming that you are using the date field in the table, you could use something like ... "SELECT * FROM table WHERE date = date("Y-m-d") ORDER BY id DESC"; Quote Link to comment Share on other sites More sharing options...
webent Posted June 21, 2008 Share Posted June 21, 2008 As a further note though, don't use date as a field name... and you may also want to take into consideration time zones... Quote Link to comment Share on other sites More sharing options...
Nexy Posted June 21, 2008 Author Share Posted June 21, 2008 When I try to set date_default_timezone_set('EST'); I get an error saying undefined date function. I'm using php 5.2. Any ideas? Thank You! Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 provided you have the date in raw format(strtotime format), you can do either.. I have a get_midnight function which basically gets the day today and calculates the exact second that midght today hit and then I do a query for everything with a date greater than that value. That'd give you everthing that was done today. Hope that helped Edit: here's the get_midnight function.. function get_midnight($timestamp) { $day = date("j", $timestamp); $month = date("F", $timestamp); $year = date("Y", $timestamp); $midnight = strtotime("$month $day $year"); return $midnight; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.