Jump to content

[SOLVED] Why is this showing the wrong date


AdRock

Recommended Posts

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 ;
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.