Kemik Posted September 14, 2007 Share Posted September 14, 2007 Hello all, Can you check this code and tell me where I'm going wrong please? <?php if ($row->datetime == date("Y-m-d")) { $datetime = date("H:i", strtotime($row->datetime)); } else { $datetime = date("d/m H:i", strtotime($row->datetime)); }?> I'm unsure how I would do the if part of the statement as the datetime is in SQL Datetime format. I know I need to say its strtotime but I'm not sure where to put it. Link to comment https://forums.phpfreaks.com/topic/69318-solved-if-todays-date-dont-display-date/ Share on other sites More sharing options...
Kemik Posted September 14, 2007 Author Share Posted September 14, 2007 Solved <?php if (date("Y-m-d", strtotime($row->datetime)) == date("Y-m-d")) { $datetime = date("H:i", strtotime($row->datetime)); } else { $datetime = date("d/m/Y H:i", strtotime($row->datetime)); } ?> Link to comment https://forums.phpfreaks.com/topic/69318-solved-if-todays-date-dont-display-date/#findComment-348311 Share on other sites More sharing options...
Barand Posted September 14, 2007 Share Posted September 14, 2007 I was just on the point of posting an identical solution. Explanation : $row->datetime contains the time element whereas date('Y-m-d') has 0 time element (ie YYYY-MM-DD 00:00:00) so the two are not equal. Link to comment https://forums.phpfreaks.com/topic/69318-solved-if-todays-date-dont-display-date/#findComment-348317 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.