Get Days difference between two dates !
Examples of what the function can return;
- Today
- Yesterday
- Tomorrow
- In 2 days
- In 6 days
- 5 days ago
- Thursday 18 January
- Tuesday 19 January 2013
- <?php
- $my_timestamp = “2013-09-01 11:22:47”;
- echo relative_date(strtotime($my_timestamp ));
- function relative_date($time)
- {
- $today = strtotime(date(‘M j, Y’));
- $reldays = ($time – $today)/86400;
- if ($reldays >= 0 && $reldays < 1)
- {
- return ‘Today’;
- } else if ($reldays >= 1 && $reldays < 2) {
- return ‘Tomorrow’;
- } else if ($reldays >= -1 && $reldays < 0) {
- return ‘Yesterday’;
- }
- if (abs($reldays) < 7) {
- if ($reldays > 0) {
- $reldays = floor($reldays);
- return ‘In ‘ . $reldays . ‘ day’ . ($reldays != 1 ? ‘s’ : ”);
- } else {
- $reldays = abs(floor($reldays));
- return $reldays . ‘ day’ . ($reldays != 1 ? ‘s’ : ”) . ‘ ago’;
- }
- }
- if (abs($reldays) < 182) {
- return date(‘l, j F’,$time ? $time : time());
- } else {
- return date(‘l, j F, Y’,$time ? $time : time());
- }
- }
- ?>
Source : search ,geekshangout.com