[PHP] Bug with mktime??

2004-08-30 Thread John Clegg
Hi
I have been using mktime() to determine the next 12 months for a 
program, and i have discovered what seems a bug in the function.

The following code...
?php
for($i=0;$i  12;$i++){
$currentDate = date(d m Y,mktime(0, 0, 0,date(m)+$i , date(d), 
date(Y)));
$currentDateArray = explode( ,$currentDate);
$currentMonth = $currentDateArray[1];
$currentYear = $currentDateArray[2];
echo $i : $currentMonth : $currentYear br;
}

 gives the following output:
$i : Month: Year
0 : 08 : 2004
1 : 10 : 2004
2 : 10 : 2004
3 : 12 : 2004
4 : 12 : 2004
5 : 01 : 2005
6 : 03 : 2005
7 : 03 : 2005
8 : 05 : 2005
9 : 05 : 2005
10 : 07 : 2005
11 : 07 : 2005
This output has a problem.
Does anyone have any suggestions on what other functions I could use 
other than mktime to build dates ???

Cheers
John Clegg
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Bug with mktime??

2004-08-30 Thread Jason Wong
On Tuesday 31 August 2004 05:53, John Clegg wrote:

 I have been using mktime() to determine the next 12 months for a
 program, and i have discovered what seems a bug in the function.

 The following code...

 ?php
 for($i=0;$i  12;$i++){

 $currentDate = date(d m Y,mktime(0, 0, 0,date(m)+$i , date(d),

Try using date('n'). Leading zeros are interpreted in octal.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
You don't have to be nice to people on the way up if you're not planning on
coming back down.
-- Oliver Warbucks, Annie
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Bug with mktime??

2004-08-30 Thread Michal Migurski
 gives the following output:
$i : Month: Year
0 : 08 : 2004
1 : 10 : 2004
2 : 10 : 2004
3 : 12 : 2004
4 : 12 : 2004
5 : 01 : 2005
6 : 03 : 2005
7 : 03 : 2005
8 : 05 : 2005
9 : 05 : 2005
10 : 07 : 2005
11 : 07 : 2005
Your bug is being caused by short months. If you ask mktime() to give 
you the 31st day of november, it will assume you mean the 1st of 
december. You can see more clearly what's going on if you shorten your 
code, like so:

for($i=0;$i  12;$i++) {
echo {$i}: ;
echo date(d m Y,mktime(0, 0, 0,date(m)+$i , date(d), date(Y)));
echo 'br';
}
It's a good thing you're trying this today; if you had tried it a few 
days ago, you wouldn't have had any idea that your method wasn't 
working.

--
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php