|
Posted by Moot on 01/05/07 13:25
Rik wrote:
> David Gillen wrote:
> > Moot said:
> >> Krustov wrote:
> >>>> $ganja=date("D dS M h:i A",time()+600);
> >>>>
> >>>
> >>> That worked fine - thanks to both users .
> >>>
> >>
> >> Or, if you're like me and don't want to figure out the correct number
> >> to add for various intervals, a more plain-english style solution
> >> would be:
> >> $ganja = date("D dS M h:i A",strtotime("+10 minutes"));
> >>
> > Haha, I like that. Anything that makes something easier to understand
> > when scanning the code is good.
>
> Well strtotime has it's advantages. However, it's poorly documented and
> sometimes unpredictable. After a short while I reverted back to working
> with adding/subtracting timestamps, just with a comment in the code beside
> it. Equally (or even more) clear thans to the comment, and 100%
> predictable.
> --
> Rik Wasmus
Agreed. strtotime has some annoying flaws that aren't officially
documented. For an illustration, try the following code:
<?php
echo date('m/d/Y', strtotime('3/31/2006')) . " - Today\n";
echo date('m/d/Y', strtotime('-1 month', strtotime("3/31/2006"))) . " -
Last Month (expect: 2/??/2006)\n";
echo date('m/d/Y', strtotime('+1 month', strtotime("3/31/2006"))) . " -
Next Month (expect: 4/??/2006)\n";
?>
This example shows how strtotime's handling of months could really
screw up logic expecting it to work in a different way than it actually
does (I should know, I've learned it the hard way). Since there are 28
days in Feb, strtotime adds the 3 extra days (to 31) and ends up at
March 3rd, similar problem with April, which has 30 days, so the extra
1 puts it to May 1st.
I've only really had a problem with strtotime with months, though.
Most other time intervals seem to work as expected.
- Moot
[Back to original message]
|