Get Date like 4 days ago.. 5hours ago.. etc.

$cInfo->date = Your_Date;
$date1=date('Y-m-d', strtotime($cInfo->date));
$date2=date('Y-m-d  H:i:s');
$diff =  (int)abs((strtotime($date1) - strtotime($date2))/(60*60*24));
if($diff == 0){
$datetime1 = date_create($cInfo->date);
$datetime2 = date_create(date('Y-m-d  H:i:s'));
$interval = date_diff($datetime1, $datetime2);
$date = $interval->format('%h:%i');
} else if($diff  > 0 && $diff < 7){
$date = date("D", strtotime($cInfo->date));
} else {
$date = date('F m, Y g:i A', strtotime($cInfo->date));
}

echo $date

No comments:

Post a Comment

Featured post

A23 Rummy - Safe Secure Gaming Platform

A23 Rummy is a popular online rummy platform in India. It is owned and operated by Head Digital Works Private Limited. The platform offers...