about 9 years ago
Passing date to the function and returning the time passed or elapsed when it was commented/posted. It is very useful when you have comment section in your website and you want to show how earlier comment was posted.
/** * Creating the date difference in the correct text format. * * @param date $recordCreated. * @return string $finalResult Response. */ function getTimeDifferenceFormat($recordCreated) { $date = date('Y-m-d H:i:s'); $datetime1 = new DateTime($date); $datetime2 = new DateTime($recordCreated); $interval = $datetime1->diff($datetime2); $dateFormat = $interval->format('%a:%h:%i:%s'); $data = explode(':', $dateFormat); $finalResult = ""; if (!empty($data)) { $days = $data[0]; $hours = $data[1]; $minutes = $data[2]; $seconds = $data[3]; if ($days == 0) { if ($hours == 0) { if ($minutes == 0) { $finalResult = "few seconds ago."; } else { $finalResult = ($minutes == 1) ? $minutes . " minute ago." : $minutes . " minutes ago."; } } else { $finalResult = ($hours == 1) ? $hours . " hour ago." : $hours . " hours ago."; } } else { $finalResult = ($days == 1) ? $days . " day ago." : $days . " days ago."; } } else { $finalResult = "problem"; } return $finalResult; }
Starting with Chrome version 45, NPAPI is no longer supported for Google Chrome. For more information, see Chrome and NPAPI (blog.chromium.org).
Firefox and Microsoft Internet Explorer are recommended browsers for websites using java applets.
Chrome Version Support
Are you sure, you want to delete this comment?
Sign up using
0 Comment(s)