Problem with dates

Topics: Developer Forum, User Forum
Jan 28, 2013 at 5:25 PM

Hello,


I wish someone could help me since I am not able to read the dates of an excel file. The format of dates is as follows 2012/10/10. Now how can I, through the PHPExcel to sense that this is a date for it to turn into TO_DATE ('2012 / 10/10 'yyyy.mm.dd'). Someone can help me?

Coordinator
Jan 28, 2013 at 7:05 PM
PHPExcel_Shared_Date::isDateTime(
    $objPHPExcel->getActiveSheet()->getCell('A1');
);

will identify if cell A1 contains a date value, returning a simple boolean TRUE or FALSE.

 

PHPExcel_Shared_Date::ExcelToPHP(
    $objPHPExcel->getActiveSheet()->getCell('A1')->getValue();
);

or

PHPExcel_Shared_Date::ExcelToPHPObject(
    $objPHPExcel->getActiveSheet()->getCell('A1')->getValue();
);

will turn an Excel datetimestamp from cell A1 into a unix timestamp or PHP DateTime object respectively, and these can then be formatted as a date string using standard PHP date format functions.

Jan 29, 2013 at 10:17 AM
Edited Jan 29, 2013 at 10:41 AM

The first instruction you gave me returns false, then does not recognize that is a date. 

The remaining instructions do not help me, since it scans the entire line will always be that he is an object. I want him to make sure it's a date

 

Edit: Solutions: PHPExcel_Cell::setValueBinder( new PHPExcel_Cell_AdvancedValueBinder() );  thz anyway

Coordinator
Jan 29, 2013 at 10:41 AM
zmk wrote:

The first instruction you gave me returns false, then does not recognize that is a date. 

In that case, the value in cell A1 isn't an Excel datetime value.... only exceptions are if you had setReadDataOnly() TRUE when you loaded the file, or if the "date" was actually a string and not an Excel datetimestamp.

zmk wrote:

The remaining instructions do not help me, since it scans the entire line will always be that he is an object. I want him to make sure it's a date

 Don't understand what you mean. "scans the entire line"? What is scanning where?