note 8385 added to strftime
| From: | johnfree at pacbell dot net | Date: | Sat, 09 Sep 2000 21:08:16 +0000 |
| Subject: | note 8385 added to strftime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4623@lists.php.net to get a copy of this message | ||
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