Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Date error exposed in both PHP and Perl

Date error exposed in both PHP and Perl
Thread Tools
Fresh-Faced Recruit
Join Date: Oct 2000
Location: Ypsilanti, MI, USA
Status: Offline
Reply With Quote
Nov 16, 2000, 03:34 PM
 
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
Reply With Quote
Nov 16, 2000, 05:49 PM
 
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
Reply With Quote
Nov 16, 2000, 09:45 PM
 
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
Reply With Quote
Nov 17, 2000, 09:56 PM
 
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
Reply With Quote
Nov 18, 2000, 07:38 AM
 
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
Reply With Quote
Nov 18, 2000, 10:48 PM
 
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.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:44 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2