Discussion:
I have a mktime problem
Jay Blanchard
2006-03-30 21:29:06 UTC
Permalink
I'm having an weird issues with the date and mktime function thing
getting unexpected results, and I was wondering if y'all could help clue
me in as to what is wrong.
Here's the code I'm running:
echo date(M, mktime(0,0,0,2)) . "\n"; Where the 2 is the month.
Now when I put in the number 1 in the month slot I get Jan When I put in
3 I get Mar When I put in 4 I get Apr Etc.
However, when I put in 2 I get Mar and not Feb.

What's up with that? What am I doing wrong here? Should I get some
sleep?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Bronislav Klucka
2006-03-30 21:41:14 UTC
Permalink
Every missing argument is set to current value, so now you have

mktime(0,0,0,2,30,2006), that is March, the 2nd.

Brona
Post by Jay Blanchard
I'm having an weird issues with the date and mktime function thing
getting unexpected results, and I was wondering if y'all could help clue
me in as to what is wrong.
echo date(M, mktime(0,0,0,2)) . "\n"; Where the 2 is the month.
Now when I put in the number 1 in the month slot I get Jan When I put in
3 I get Mar When I put in 4 I get Apr Etc.
However, when I put in 2 I get Mar and not Feb.
What's up with that? What am I doing wrong here? Should I get some
sleep?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jay Blanchard
2006-03-30 21:41:19 UTC
Permalink
[snip]
I think this is happening because the day is being filled in by PHP as
30. Today is March 30th.

Try these:

echo date("d M Y", mktime(0,0,0,2)) . "\n"; //02 Mar 2006
echo date("d M Y", mktime(0,0,0,3)) . "\n"; //30 Mar 2006

PHP thinks you mean Feb 30th, which doesn't exist. So it adds 2 days and
ends up being Mar 2nd.
[/snip]

Thanks! That fixed it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Moseby
2006-03-30 21:38:56 UTC
Permalink
Post by Jay Blanchard
I'm having an weird issues with the date and mktime function thing
getting unexpected results, and I was wondering if y'all
could help clue
me in as to what is wrong.
echo date(M, mktime(0,0,0,2)) . "\n"; Where the 2 is
the month.
Now when I put in the number 1 in the month slot I get Jan
When I put in
3 I get Mar When I put in 4 I get Apr Etc.
However, when I put in 2 I get Mar and not Feb.
What's up with that? What am I doing wrong here? Should I get some
sleep?
It seems to have something to do with the fact that Feb has only 28 or 29
days, and today is the 30th.

echo date(M, mktime(0,0,0,2,28)) . "\n";

It will return "Mar".

JM
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Jim Moseby
2006-03-30 21:41:02 UTC
Permalink
Post by Jim Moseby
Post by Jay Blanchard
I'm having an weird issues with the date and mktime function thing
getting unexpected results, and I was wondering if y'all
could help clue
me in as to what is wrong.
echo date(M, mktime(0,0,0,2)) . "\n"; Where the 2 is
the month.
Now when I put in the number 1 in the month slot I get Jan
When I put in
3 I get Mar When I put in 4 I get Apr Etc.
However, when I put in 2 I get Mar and not Feb.
What's up with that? What am I doing wrong here? Should I get some
sleep?
It seems to have something to do with the fact that Feb has
only 28 or 29
days, and today is the 30th.
echo date(M, mktime(0,0,0,2,28)) . "\n";
It will return "Mar".
JM
Whoops, "Feb" I meant to say.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...