AdRock Posted April 8, 2009 Share Posted April 8, 2009 I have a function that converts todays date to "today", yesterdays date to "yesterday" and any other date is left normal The problem is that it is showing todays date as yesterday and yesterdays date is a normal date here is the code <?php function change_date($time) { $today = strtotime(date('F d, Y, h:i:s A')); $day = ($time - $today)/86400; if ($day >= 0 && $day < 1) { return '<b>Today</b>'.date(', h:i:s A', $time ? $time : time()); } else if ($day >= -1 && $day < 0) { return '<b>Yesterday</b>'.date(', h:i:s A', $time ? $time : time()); } else { return date('F d, Y, h:i:s A',$time ? $time : time()); } } //time stamp from my database etc $my_timestamp = "2009-04-08 14:32:18"; //store the results of the function into $my_relative_time $my_relative_time = change_date(strtotime($my_timestamp )); //output echo $my_relative_time ; ?> Link to comment https://forums.phpfreaks.com/topic/153205-solved-why-is-this-showing-the-wrong-date/ Share on other sites More sharing options...
AdRock Posted April 8, 2009 Author Share Posted April 8, 2009 $today = strtotime(date('F d, Y, h:i:s A')); should have been $today = strtotime(date('F d, Y')); Link to comment https://forums.phpfreaks.com/topic/153205-solved-why-is-this-showing-the-wrong-date/#findComment-804795 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.