/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Change the following constants to suit your language */ /* Change the following date format to your taste */ /* The functions takes the date as a timestamp */ function DateToWords($time) { $_word = ""; /* Get the difference between the current time and the time given in days */ /* If some forward time is given return error */ if($days < 0) { return -1; } switch($days) { case 0: $_word = STRING_TODAY; break; case 1: $_word = STRING_YESTERDAY; break; case ($days >= 2 && $days <= 6): break; case ($days >= 7 && $days < 14): $_word= STRING_WEEK; break; case ($days >= 14 && $days <= 365): break; } return $_word; }
URL: http://www.codediesel.com/php/printing-relative-dates-in-php/