Page 1 of 1
Date problem
Posted: Thu Jan 24, 2008 5:06 pm
by PhpDog
I'm grabbing data from a MS SQL 2005 server and using:
$startDate = date("d-m-Y", strtotime($row[2]));
to change the data from the returned array into a date string with format d-m-Y for my purpose.
A data record of 21/12/1989 00:00:00 gives me 21-12-1989 which is fine.
However a data record of 31/12/2039 00:00:00 gives me 01-01-1970 which is anything but fine.
What gives guys?
I'm using PHP version 5.2.5
Re: Date problem
Posted: Thu Jan 24, 2008 8:41 pm
by SidewinderX
From
http://us3.php.net/manual/en/function.time.php
Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.) Additionally, not all platforms support negative timestamps, therefore your date range may be limited to no earlier than the Unix epoch. This means that e.g. dates prior to Jan 1, 1970 will not work on Windows, some Linux distributions, and a few other operating systems. PHP 5.1.0 and newer versions overcome this limitation though.
Re: Date problem
Posted: Fri Jan 25, 2008 3:32 am
by PhpDog
I see .. thanks for the heads up. However, the last part of the quote "... PHP 5.1.0 and newer versions overcome this limitation though." fell flat for me on 5.2.5.
I guess I'll have to write a cheesy function to overcome this.
Re: Date problem
Posted: Fri Jan 25, 2008 9:20 am
by Ollie Saunders
I guess I'll have to write a cheesy function to overcome this.
I think you'll have to write a couple of classes to overcome that and have the bcmath extension enabled. You're Better off looking for existing code.
Re: Date problem
Posted: Fri Jan 25, 2008 10:02 am
by PhpDog
This worked for me:
Code: Select all
function formatDate($input)
{
$months[1] = "Jan";
$months[2] = "Feb";
$months[3] = "Mar";
$months[4] = "Apr";
$months[5] = "May";
$months[6] = "Jun";
$months[7] = "Jul";
$months[8] = "Aug";
$months[9] = "Sep";
$months[10] = "Oct";
$months[11] = "Nov";
$months[12] = "Dec";
$dates = explode(" ", $input);
$month = array_keys($months, $dates[0]);
// --- if month number < 10 add 0 prefix -------
if($month[0] < 10)
{
$month[0] = "0".strval($month[0]);
}
// --- if(day number < 10 add 0 prefix ---------
if($dates[1] < 10)
{
$dates[1] = "0".strval($dates[1]);
}
return $dates[1]."-".$month[0]."-".$dates[2];
}
Re: Date problem
Posted: Fri Jan 25, 2008 10:16 am
by Ollie Saunders
Ah OK. You aren't doing what I thought you were.
Re: Date problem
Posted: Sat Jan 26, 2008 11:56 am
by SidewinderX
PhpDog wrote:I see .. thanks for the heads up. However, the last part of the quote "... PHP 5.1.0 and newer versions overcome this limitation though." fell flat for me on 5.2.5.
I guess I'll have to write a cheesy function to overcome this.
I'm pretty sure they are referring to the latter limitation - not both limitation
(s).