0

I'm using PHPExcel to read the data, and then validating the data. Problem I'm getting is all the data is validating except I don't know how to check the array if it has a date or not. Problem is not a format, problem is I'm unable to find a way to check whether it is a date or another string or integer. These are one of my value in a date cell in Excel file. i.e ;

1/2/15 17:24
1/7/15 12:00
1/9/15 11:57
2
  • Use this link stackoverflow.com/questions/19958292/… Commented Jan 31, 2017 at 11:58
  • @Veritasian i thinnk you havent read my question. Problem is not a specific format or a range. I just want to know it is a date or not. Commented Jan 31, 2017 at 12:03

2 Answers 2

0

For each cell you can check if this is a date :

if(PHPExcel_Shared_Date::isDateTime($cellobj)) {
    //it's a date
} 
Sign up to request clarification or add additional context in comments.

2 Comments

Ok i m trying this!
No, it doesn't work on a cell value; that's why the argument is $cellobj, because it requires a cell object
0

you have to check your current version of PHP because new functions are not available in old versions. Is you date format is fixed? if yes then there is function checkdate (). it returns true on valid date.

bool checkdate ( int $month , int $day , int $year )

http://php.net/manual/en/function.checkdate.php

Checks the validity of the date formed by the arguments. A date is considered valid if each parameter is properly defined.

My suggestion is, explode() 1/2/15 17:24 data from excel and then pass it to the checkdate() function, if it returns true then this is "DATE" or this entire excel column contains DATE

3 Comments

this does not work. I have thousands of cells in the date column and in each cell value. It takes so much time to explode and then pass it to the checkdate function.
get all csv data in an array and then process it! I have used PHPExcel on millions of records! or can you run this php script from command line? If you are running it through the webpage then you have to make some configuration changes for memory, array max length, execution time, priority of the job etc...
ok so in each value of cell. After exploding can you just guide me how to put every value to match with the checkdate variables like $month , $year, $date

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.