php date not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

php date not working

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: php date not working

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: php date not working

Post 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?
User avatar
pavanpuligandla
Forum Contributor
Posts: 130
Joined: Thu Feb 07, 2008 8:25 am
Location: Hyderabad, India

Re: php date not working

Post 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..
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: php date not working

Post 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)
Post Reply