Page 1 of 1
php date not working
Posted: Tue Dec 02, 2008 1:21 pm
by pavanpuligandla
hii,
i've 5 columns in my excel sheet,
SNO Name Age Date Province
i gave today's date under the "date" column field as "12/3/2008"(choosen first format for date in my excel sheet)
when i read the excel sheet using php excel reader class, then the date is being displayed as,
"04/12/2008".
can anyone please help me,, why is this happening..?
many regards.
Re: php date not working
Posted: Tue Dec 02, 2008 4:12 pm
by pickle
Month/Day/Year is the United States way of stating the date, Day/Month/Year is everyone else.
Is it really adding a day like your example shows, or is it just reversing the month & day order?
Re: php date not working
Posted: Tue Dec 02, 2008 4:52 pm
by Mark Baker
pavanpuligandla wrote:i gave today's date under the "date" column field as "12/3/2008"(choosen first format for date in my excel sheet)
when i read the excel sheet using php excel reader class, then the date is being displayed as,
"04/12/2008".
Are you actually storing the date as an Excel date, or as a string?
Re: php date not working
Posted: Wed Dec 03, 2008 5:22 am
by pavanpuligandla
Are you actually storing the date as an Excel date, or as a string?
yeah i'm storing it as excel date..
in php reader class,
the date formats are like the listed below;
there is no american M_DD_YYYY format..
Code: Select all
var $dateFormats = array (
0xe => "d/m/Y",
0xf => "d-M-Y",
0x10 => "d-M",
0x11 => "M-Y",
0x12 => "h:i a",
0x13 => "h:i:s a",
0x14 => "H:i",
0x15 => "H:i:s",
0x16 => "d/m/Y H:i",
0x2d => "i:s",
0x2e => "H:i:s",
0x2f => "i:s.S");
so i changed the above to american standard date..
there's no problem with database insertions..
the problem is with php reader..
Re: php date not working
Posted: Thu Dec 04, 2008 11:24 am
by Mark Baker
pavanpuligandla wrote:Are you actually storing the date as an Excel date, or as a string?
yeah i'm storing it as excel date..
in php reader class,
the problem is with php reader..
If you can read the date as the numeric Excel timestamp, the following should allow you to convert it to a PHP timestamp:
Code: Select all
function ExcelToPHP($dateValue = 0) {
if ($ExcelBaseDate == CALENDAR_WINDOWS_1900) {
$myExcelBaseDate = 25569;
// Adjust for the spurious 29-Feb-1900 (Day 60)
if ($dateValue < 60) {
--$myExcelBaseDate;
}
} else {
$myExcelBaseDate = 24107;
}
// Perform conversion
if ($dateValue >= 1) {
$utcDays = $dateValue - $myExcelBaseDate;
$returnValue = (integer) round($utcDays * 24 * 60 * 60);
} else {
$hours = round($dateValue * 24);
$mins = round($dateValue * 24 * 60) - round($hours * 60);
$secs = round($dateValue * 24 * 60 * 60) - round($hours * 60 * 60) - round($mins * 60);
$returnValue = (integer) mktime($hours, $mins, $secs);
}
// Return
return $returnValue;
} // function ExcelToPHP()
Set $ExcelBaseDate and CALENDAR_WINDOWS_1900 as appropriate for the Calendar that your workbooks are using (Windows 1900 or Mac 1904)