note 12762 deleted from function.strftime by sniper
| From: | sniper@php.net | Date: | Wed, 15 Jan 2003 09:37:20 +0000 |
| Subject: | note 12762 deleted from function.strftime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-42161@lists.php.net to get a copy of this message | ||
"
I've seen some horribly long scripts to find the diff between 2 dates, but here's what I
did to find how old I am! Works only for dates after the Unix epoch, (ie) 1.1.1970
<?php
$diff = time() - mktime(8,30,0,1,12,1978,0);
/*Jan 12th 1978, 8:30 AM*/
$week = strftime("%W",$diff);
$year = strftime("%Y",$diff) - 1970;
$day = strftime("%w",$diff);
echo "($year years, $week weeks and $day days)";
?>
"
This example will not work right because it doesn't take into account the time zone offset from
time() and has jan 1 1970 hard coded.
If you have a xBSD system take a look at 'time -r 0' and you will see its not Jan 1, 1970.
The reason why it looks like it works is because you don't look at time parts less than your
time zone offset.