PHP BUG!

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
savagestudio
Forum Newbie
Posts: 4
Joined: Tue Aug 31, 2010 7:38 am

PHP BUG!

Post by savagestudio »

hello evrybody !
i have a probleme with mktime() and i think it is a bug, it do it only with the month Oct here is my very simple code:

Code: Select all

<?php
$themonth=8;
$prevM = date("M", mktime(0, 0, 0, ($themonth - 1) ));
$nextM = date("M", mktime(0, 0, 0, ($themonth + 1) ));
echo '$prevM='.$prevM.'<br />$nextM='.$nextM;

?>
//it trace :
// $prevM=Jul // ok
//$nextM=Oct // not ok!


BUT IF I PUT THE MONTH TO 9 :

Code: Select all

themonth=9;
$prevM = date("M", mktime(0, 0, 0, ($themonth - 1) ));
$nextM = date("M", mktime(0, 0, 0, ($themonth + 1) ));
echo '$prevM='.$prevM.'<br />$nextM='.$nextM;
//it trace :
$prevM=Aug // ok
$nextM=Oct // ok!


AND:

Code: Select all

themonth=10;
$prevM = date("M", mktime(0, 0, 0, ($themonth - 1) ));
$nextM = date("M", mktime(0, 0, 0, ($themonth + 1) ));
echo '$prevM='.$prevM.'<br />$nextM='.$nextM;


trace $prevM=Oct //not ok
$nextM=Dec // ok!


the thing i dont follow is that it was working before !
Last edited by savagestudio on Tue Aug 31, 2010 8:16 am, edited 1 time in total.
savagestudio
Forum Newbie
Posts: 4
Joined: Tue Aug 31, 2010 7:38 am

Re: PHP BUG! Please help!!

Post by savagestudio »

AND IF I TYPE :

Code: Select all

$prevM = date("M", mktime(0, 0, 0, 9 ));
$nextM = date("M", mktime(0, 0, 0, 11));
echo '$prevM='.$prevM.'<br />$nextM='.$nextM;
it trace:
$prevM=Oct
$nextM=Dec


it doesn't make any sense
i can send the url of this code for see that i am not lying i need help !! 8O
savagestudio
Forum Newbie
Posts: 4
Joined: Tue Aug 31, 2010 7:38 am

Please help PHP BUG!

Post by savagestudio »

Please some help ?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP BUG!

Post by AbraCadaver »

From the manual: "Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time."

So I assume that since you omitted the day it uses todays date, 31 as the day argument for September which is not valid (only 30 days in September) so it rolls over to the next month. Try this:

Code: Select all

$prevM = date("M", mktime(0, 0, 0, 9, 1));
$nextM = date("M", mktime(0, 0, 0, 11, 1));
echo '$prevM='.$prevM.'<br />$nextM='.$nextM;
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
savagestudio
Forum Newbie
Posts: 4
Joined: Tue Aug 31, 2010 7:38 am

Re: PHP BUG!

Post by savagestudio »

THANKS A LOT, I WAS STARTING TO PUL MY HAIR OFF :banghead: i was far from finding the answer :crazy: Thanks and have a good day! :D
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: PHP BUG!

Post by Weirdan »

mktime(0,0,0, 9) means mktime(0,0,0, 9, date('j'), date('Y'));
And since today is 31st you're asking for 31st of September. Last time I checked September had only 30 days, thus mktime() assumes you're asking for the 1st of October.
Post Reply