function timeAgo($timestamp){
date_default_timezone_set("Asia/Karachi");
$datetime1=new DateTime("now");
$datetime2=date_create($timestamp);
$diff=date_diff($datetime1, $datetime2);
$timemsg='';
if($diff->y > 0){
$timemsg = $diff->y .' year'. ($diff->y > 1?"'s":'');
}
else if($diff->m > 0){
$timemsg = $diff->m . ' month'. ($diff->m > 1?"'s":'');
}
else if($diff->d > 0){
$timemsg = $diff->d .' day'. ($diff->d > 1?"'s":'');
}
else if($diff->h > 0){
$timemsg = $diff->h .' hour'.($diff->h > 1 ? "'s":'');
}
else if($diff->i > 0){
$timemsg = $diff->i .' minute'. ($diff->i > 1?"'s":'');
}
else if($diff->s > 0){
$timemsg = $diff->s .' second'. ($diff->s > 1?"'s":'');
}
$timemsg = $timemsg.' ago';
echo $timemsg;
}
date_default_timezone_set("Asia/Karachi");
$datetime1=new DateTime("now");
$datetime2=date_create($timestamp);
$diff=date_diff($datetime1, $datetime2);
$timemsg='';
if($diff->y > 0){
$timemsg = $diff->y .' year'. ($diff->y > 1?"'s":'');
}
else if($diff->m > 0){
$timemsg = $diff->m . ' month'. ($diff->m > 1?"'s":'');
}
else if($diff->d > 0){
$timemsg = $diff->d .' day'. ($diff->d > 1?"'s":'');
}
else if($diff->h > 0){
$timemsg = $diff->h .' hour'.($diff->h > 1 ? "'s":'');
}
else if($diff->i > 0){
$timemsg = $diff->i .' minute'. ($diff->i > 1?"'s":'');
}
else if($diff->s > 0){
$timemsg = $diff->s .' second'. ($diff->s > 1?"'s":'');
}
$timemsg = $timemsg.' ago';
echo $timemsg;
}
If you love this tutorials please share it or comment below.
0 comments:
Post a Comment
Please Don't write wrong comments.
.
Please write good comments or mistakes ...