php date() problems ... again

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wanger220
Forum Newbie
Posts: 19
Joined: Tue Feb 02, 2010 8:44 pm

php date() problems ... again

Post by wanger220 »

What is going on here? This was just a quick fix to apply a date label to a document ... it worked fine until today, the last day of the month. I thought php takes the local machine's time zone, so I doubt it's that kind of error. Any explanations?

Code: Select all


$thismonth = date("m");
$f_thismonth = date("F");
$thisday = date("d");
$nextmonth = date("m",mktime(0,0,0,date("m")+1,date("d"),date("y")));
$f_nextmonth = date("F",mktime(0,0,0,date("m")+1,date("d"),date("y")));
$monthafter = date("m",mktime(0,0,0,date("m")+2,date("d"),date("y")));
$f_monthafter = date("F",mktime(0,0,0,date("m")+2,date("d"),date("y")));

echo "Today's date: " . $thismonth . " " . $thisday . "<p>";

echo "Next month: " . $f_nextmonth . " " . $nextmonth . "<p>";

echo "Month after: " . $f_monthafter . " " . $monthafter;

?>

It currently outputs:
Today's date: 03 31

Next month: May 05

Month after: May 05
wanger220
Forum Newbie
Posts: 19
Joined: Tue Feb 02, 2010 8:44 pm

Re: php date() problems ... again

Post by wanger220 »

Never mind ... figured it out.

For those wondering, because I included the day (date("d")) in the mktime string, php adds one month from today, which would be April 31 == May 1.
Post Reply