Re: note 8385 added to strftime
| From: | J. M. Castagnetto | Date: | Sun, 10 Sep 2000 02:50:26 +0000 |
| Subject: | Re: note 8385 added to strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4634@lists.php.net to get a copy of this message | ||
Have you looked at the comments in strtotime()? See
also: http://bugs.php.net/bugs.php?id=4833
Are you using the latest version of PHP? This was a
bug in 4.0.0 apparently.
I tried this code:
function a($date_str) {
$uts = strtotime($date_str);
$y = strftime("%Y", $uts);
$m = strftime("%m", $uts);
$d = strftime("%d", $uts);
print "DVdate: $date_str, m/d/y $m/$d/$y strfdate: " .
strftime("%D", $uts)."\n";
}
a("1/02/2003");
a("1/01/2003");
and it gave the expected answers using the latest PHP.
--- johnfree@pacbell.net wrote:
>
> I think my previous complaint about the month was
> incorrect, rather it it the DAY that is one off! To
> wit:
>
> $uts = strtotime($date_str);
> $y = strftime("%Y", $uts);
> $m = strftime("%m", $uts);
> $d = strftime("%d", $uts);
> print "DVdate: $date_str, m/d/y $m/$d/$y strfdate:
> " . strftime("%D", $uts);
>
> Here is the printout for two values of $date_str:
>
> //DVdate: 1/02/2003, m/d/y 01/01/2003 strfdate:
> 01/01/03
> //DVdate: 1/01/2003, m/d/y 12/31/2002 strfdate:
> 12/31/02
>
> My somewhat cumbersome solution is to use good old
> mktime() to add the day back:
>
> $uts = strtotime($date_str);
> $y = strftime("%Y", $uts);
> $m = strftime("%m", $uts);
> $d = strftime("%d", $uts);
> $uts = mktime(0,0,0, $m, $d + 1, $y);
> $y = strftime("%Y", $uts);
> $m = strftime("%m", $uts);
> $d = strftime("%d", $uts);
> print "DVdate: $date_str, m/d/y $m/$d/$y strfdate:
> " . strftime("%D", $uts);
>
> //DVdate: 1/02/2003, m/d/y 01/01/2003 strfdate:
> 01/01/03
> //DVdate: 1/01/2003, m/d/y 01/01/2002 strfdate:
> 01/01/02
>
> If anyone can see a better way to do this I'd like
> to hear it!
> thanks.
>
>
> http://www.php.net/manual/function.strftime.php
>
>
> --
> PHP Notes Mailing List (http://www.php.net/)
> To unsubscribe, e-mail:
> php-notes-unsubscribe@lists.php.net
> For additional commands, e-mail:
> php-notes-help@lists.php.net
> To contact the list administrators, e-mail:
> php-list-admin@lists.php.net
>
=====
--- Jesus M. Castagnetto (jcastagnetto@yahoo.com)
__________________________________________________
Do You Yahoo!?
Yahoo! Mail - Free email you can access from anywhere!
http://mail.yahoo.com/