Menu

#27 Date fields are mangled. (with demo file)

open
nobody
None
5
2005-03-24
2005-03-24
Anonymous
No

Date fields formatted as mm/dd/yy or mm/dd/yyyy are
mangled (example: 03/02/05 became 03/0202/0505) on import.

Oops, first submission didn't attach a file. Here's one
that demonstrates the problem.

Discussion

  • Nobody/Anonymous

    An example tour date spreadsheet that demonstrates the error.

     
  • Nobody/Anonymous

    Logged In: NO

    Hi,

    Had the same issue. Better use the raw cell datas (cellsInfo).
    For a date type, it contains the number of days elapsed since
    the Epoch (1900-01-01)

     
  • Nobody/Anonymous

    Logged In: NO

    how would you go about using raw data from here?

    for ($i = 1; $i <= $data->sheets[0]['numRows']; $i++) {
    for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
    echo $data->sheets[0]['cells'][$i][$j];
    }
    }

     
  • omaeryx

    omaeryx - 2006-09-14

    Logged In: YES
    user_id=1420026

    This is a crappy workaround for the wrong parse of
    mm/dd/yyyy dates.

    function createDate($numValue){
    if ($numValue > 1){
    $utcDays = $numValue - ($this->nineteenFour ?
    Spreadsheet_Excel_Reader_utcOffsetDays1904 :
    Spreadsheet_Excel_Reader_utcOffsetDays);
    $utcValue = round($utcDays *
    Spreadsheet_Excel_Reader_msInADay);

    if ($this->curformat == "i/dd/yyyy"){
    $this->curformat = "m/d/Y";
    }

    $string = date ($this->curformat, $utcValue);
    $raw = $utcValue;
    }else{
    $raw = $numValue;
    $hours = floor($numValue * 24);
    $mins = floor($numValue * 24 * 60) - $hours * 60;
    $secs = floor($numValue *
    Spreadsheet_Excel_Reader_msInADay) - $hours * 60 * 60 -
    $mins * 60;
    $string = date ($this->curformat, mktime($hours,
    $mins, $secs));
    }
    return array($string, $raw);
    }

     
  • Nobody/Anonymous

    Logged In: NO

    I found the reason for this that is the date format from the Excel sheet was directly inserted into the date function in php.
    So you got date("dd/i/yyyy",$columnvalue);
    Which should have looked like date("d/m/Y",$columnvalue);

    So what is needed is that it uses the correct value here by either forcing one correct value (I do not have use for multiple formats, consistent output is better). Or link each format from Excel to a PHP date format value.

     

Log in to post a comment.