 |
 |
Date error exposed in both PHP and Perl
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Ypsilanti, MI, USA
Status:
Offline
|
|
There seems to be an error caused by some component of OS X PB regarding date calculations. Both PHP and Perl exhibit this behavior. I have not tried it with any other languages.
Calculating the last day of January, February, and March in either language (by using mktime()) yields these results: - 1998: 31 Jan, 28 Feb, 30 Mar
- 1999: 31 Jan, 28 Feb, 30 Mar
- 2000: 31 Jan, 28 Feb, 29 Mar
- 2001: 31 Jan, 01 Mar, 01 Apr
- 2002: 31 Jan, 28 Feb, 30 Mar
- 2003: 31 Jan, 28 Feb, 30 Mar
- 2004: 31 Jan, 28 Feb, 29 Mar
- 2005: 31 Jan, 01 Mar, 01 Apr
- 2006: 31 Jan, 28 Feb, 30 Mar
- 2007: 31 Jan, 28 Feb, 30 Mar
- 2008: 31 Jan, 28 Feb, 29 Mar
This error will occur for all other months subsequent to March as well, except for December. It's clearly something related to leap years, since only leap years and the following years are affected.The same code on another UNIX doesn't exhibit this error.Has anyone else run into this, in other languages perhaps?
[This message has been edited by jhurshman (edited 11-16-2000).]
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Nov 2000
Status:
Offline
|
|
i have been running into a date erro on mysql/php where the year ends up being 2020. i have been two busy with other stuff to get to the bottom of it.
is your mysql field a "date" type?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Ypsilanti, MI, USA
Status:
Offline
|
|
Originally posted by iloveOSX:
i have been running into a date erro on mysql/php where the year ends up being 2020. i have been two busy with other stuff to get to the bottom of it.
is your mysql field a "date" type?
Although I use MySQL, this particular error doesn't involve MySQL at all.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2000
Location: San Francisco, CA
Status:
Offline
|
|
If you post the code you used to calculate the date I will run it on a couple of my servers to see if I can confirm the error?
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Ypsilanti, MI, USA
Status:
Offline
|
|
Originally posted by lonbaker:
If you post the code you used to calculate the date I will run it on a couple of my servers to see if I can confirm the error?
PHP code, runs through every year from 1990 to 2010 and calculates the last day in November:
Code:
<?php
for ($i = 1990; $i <= 2010; $i++) {
$lastday = mktime (0,0,0,12,0,$i);
echo "Last day in Nov $i is: " . date("M d", $lastday) . "<br>";
}
?>
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2000
Location: San Francisco, CA
Status:
Offline
|
|
Yep,
Sure enough on my PHP 4.02 server the following output occurs:
Last day in Nov 1990 is: Nov 30
Last day in Nov 1991 is: Nov 30
Last day in Nov 1992 is: Nov 29
Last day in Nov 1993 is: Dec 01
Last day in Nov 1994 is: Nov 30
Last day in Nov 1995 is: Nov 30
Last day in Nov 1996 is: Nov 29
Last day in Nov 1997 is: Dec 01
Last day in Nov 1998 is: Nov 30
Last day in Nov 1999 is: Nov 30
Last day in Nov 2000 is: Nov 29
Last day in Nov 2001 is: Dec 01
Last day in Nov 2002 is: Nov 30
Last day in Nov 2003 is: Nov 30
Last day in Nov 2004 is: Nov 29
Last day in Nov 2005 is: Dec 01
Last day in Nov 2006 is: Nov 30
Last day in Nov 2007 is: Nov 30
Last day in Nov 2008 is: Nov 29
Last day in Nov 2009 is: Dec 01
Last day in Nov 2010 is: Nov 30
And on my PHP 3.0.15 server the following output occurs:
Last day in Nov 1990 is: Nov 30
Last day in Nov 1991 is: Nov 30
Last day in Nov 1992 is: Nov 30
Last day in Nov 1993 is: Nov 30
Last day in Nov 1994 is: Nov 30
Last day in Nov 1995 is: Nov 30
Last day in Nov 1996 is: Nov 30
Last day in Nov 1997 is: Nov 30
Last day in Nov 1998 is: Nov 30
Last day in Nov 1999 is: Nov 30
Last day in Nov 2000 is: Nov 30
Last day in Nov 2001 is: Nov 30
Last day in Nov 2002 is: Nov 30
Last day in Nov 2003 is: Nov 30
Last day in Nov 2004 is: Nov 30
Last day in Nov 2005 is: Nov 30
Last day in Nov 2006 is: Nov 30
Last day in Nov 2007 is: Nov 30
Last day in Nov 2008 is: Nov 30
Last day in Nov 2009 is: Nov 30
Last day in Nov 2010 is: Nov 30
I am going to reload PHP 3.016 on my OS X PB box and see what happens.
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|