I am trying to get the difference in time in mins, hours etc thingy. Now, for some reason I cannot get the right minutes or hours difference between two time stamps. Here is my code:
Code: Select all
$postedTime=strtotime($comment_from_db->date_posted);
$currentTime=time();
$mins=floor(($currentTime-$postedTime)/60);
if($mins<=1){
echo $mins." minute ago by";
}elseif($mins>1){
if($mins>60){
$hrs=floor($mins/60);
if($hrs>24){
}else{
if($hrs<2){
echo $hrs. " hour ago by";
}else{
echo $hrs. " hours ago by";
}
}
}else{
echo $mins." minutes ago by";
}
}What is the problem here?
I was doing a test and checked the time in seconds after an interval of 2 mins. Here are the results:
Comment posted: 1306669490
Current time: 1306683920
The difference is around 14430. This is not equal to 2 minutes. So, I am starting to think if the time I am getting is wrong? Should it have 10 digits? or less? I am not sure what is going on. Please, advice.
Thanks.