i uploaded a report website to an online server, then i tested it and found out that the time function i created to convert timestamp data in my db gives a wrong output.
And note that this only happened when it got uploaded online, the timestamp stores the right data into my db, but the time function i wrote in php is giving me wrong output.
For example, i made a report which stored the time of the report in my db with timestamp data type, but the time function gives an output of "5 hours ago", instead of "just now"....check my code below
The time function
date_default_timezone_set("Africa/Lagos");
function convertTime($timestamp)
{
$elapsed_time = strtotime($timestamp);
$current_time = time();
$time_diff = $current_time - $elapsed_time;
$seconds = $time_diff;
$minutes = round($seconds / 60);
$hours = round($seconds / 3600);
$days = round($seconds / 86400);
$weeks = round($seconds / 604800);
$months = round($seconds / 2629440);
$years = round($seconds / 31553280);
if ($seconds <= 60) : return "Just Now"; endif;
if ($minutes <= 60) : if ($minutes == 1) : return "1 minute ago"; else : return "$minutes minutes ago"; endif; endif;
if ($hours <= 24) : if ($hours == 1) : return "1 hour ago"; else : return "$hours hours ago"; endif; endif;
if ($days <= 7) : if ($days == 1) : return "1 day ago"; else : return "$days days ago"; endif; endif;
if ($weeks <= 4.3) : if ($minutes == 1) : return "1 week ago"; else : return "$weeks weeks ago"; endif; endif;
if ($months <= 12) : if ($months == 1) : return "1 month ago"; else : return "$months months ago"; endif; endif;
if ($years == 1) : return "1 year ago"; else : return "$years years ago"; endif;
};
Updated
This is the output i get immediately i make a report
For example New Report Made 5 Hours Ago
What i expect to see is New Report Made Just Now
And then a minute later i expect to see New Report Made One Minute Ago
This was working fine in my localhost, until i uploaded it online