katlis Posted April 14, 2009 Share Posted April 14, 2009 I have a table with a timestamp field that looks like 2009-04-14 10:46:26. I've tried just about everything to pull all records for "yesterday's" date but nothing comes back. Any help is greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/ Share on other sites More sharing options...
Mchl Posted April 14, 2009 Share Posted April 14, 2009 WHERE DATE(timestampField) = CURDATE()-1 Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810130 Share on other sites More sharing options...
katlis Posted April 14, 2009 Author Share Posted April 14, 2009 Thanks! I came across many (many!) examples, but never that. Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810219 Share on other sites More sharing options...
fenway Posted April 15, 2009 Share Posted April 15, 2009 Hold on a sec... you have to specify INTERVAL when "subtracting" dates like that!!!! Â WHERE DATE(timestampField) = CURDATE() - INTERVAL 1 DAY Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810600 Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 CURDATE can return integer if needed Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810602 Share on other sites More sharing options...
fenway Posted April 15, 2009 Share Posted April 15, 2009 CURDATE can return integer if needed Yes, it will return in numeric context -- but DATE() won't! Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810610 Share on other sites More sharing options...
Mchl Posted April 15, 2009 Share Posted April 15, 2009 Maybe it depends on SQL_MODE. Anyway works for me. Quote Link to comment https://forums.phpfreaks.com/topic/154116-select-where-date-yesterday-from-timestamp/#findComment-810641 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.