AdRock Posted April 7, 2009 Share Posted April 7, 2009 I have some dates in my database and some of them would be from today and yesterday. How would I change the date from the actual date to "today" if the date is today and "yesterday" if the dates was yesterday? Link to comment https://forums.phpfreaks.com/topic/153061-change-todays-date-to-today/ Share on other sites More sharing options...
revraz Posted April 7, 2009 Share Posted April 7, 2009 Compare to NOW() and if not equal, set to NOW() (if using mysql) Link to comment https://forums.phpfreaks.com/topic/153061-change-todays-date-to-today/#findComment-803922 Share on other sites More sharing options...
Mchl Posted April 7, 2009 Share Posted April 7, 2009 CURDATE() might actually be better choice Link to comment https://forums.phpfreaks.com/topic/153061-change-todays-date-to-today/#findComment-803923 Share on other sites More sharing options...
burningkamikaze Posted April 7, 2009 Share Posted April 7, 2009 There might be better ways but something like this would work: SELECT IF(date_field = CURDATE(), 'today', IF(date_field = DATE_SUB(CURDATE(), INTERVAL 24 HOUR), 'yesterday', date_field)) FROM table_name Of course it would then be easier to use MySQL's DATE_FORMAT function on the date field rather than doing it in PHP, to save checking for a valid date. Link to comment https://forums.phpfreaks.com/topic/153061-change-todays-date-to-today/#findComment-803924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.