Re: Friendly dates
| From: | Scott Fletcher | Date: | Mon, 01 Dec 2003 16:25:44 +0000 |
| Subject: | Re: Friendly dates | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-171484@lists.php.net to get a copy of this message | ||
Something like this, but this is not perfect.. The mktime seem to work only
for Unix/Linux and not work for Windows.
--snip--
function dateDiff($input_date)
{
//MSG #1 - Parameter1 must be in this date format --> "mm/dd/yyyy"
//MSG #2 - This script does not include fix for the leap year...
$UserInput = explode("/", $input_date);
$UserInputMonth = $UserInput[0];
$UserInputDay = $UserInput[1];
$UserInputYear = $UserInput[2];
$clockDate = mktime(0,0,0,date("m"),date("d"),date("Y"));
$inputDate = mktime(0,0,0,$UserInputMonth,$UserInputDay,$UserInputYear);
$Days = (($clockDate - $inputDate) / (24 * 3600));
$Days = round($Days);
return $Days;
}
--snip--
"Richard Davey" <rich@launchcode.co.uk> wrote in message
news:169173357265.20031201155657@launchcode.co.uk...
> Hi,
>
> I'm just wondering if anyone knows of a class/function (or easy way)
> to do the following:
>
> At the moment I display dates like this:
>
> Last message received: 30th Nov 2003 16:07
>
> This is fine, but I would like to make them more friendly like so:
>
> Last message received: Yesterday, 16:07
>
> I would ideally like to have the ranges "Today, Yesterday, This Week, Last
> Week" and beyond that I'll use the method above.
>
> I know how to actually do this from a code point of view, but think it
> must be a quite general sort of task and am all for not re-inventing
> the wheel here if someone knows/has a quick way to do this?
>
> --
> Best regards,
> Richard mailto:rich@launchcode.co.uk