How to check the date type in array in PHP

拜拜、爱过 提交于 2019-12-25 04:55:16

问题


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

回答1:


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

if(PHPExcel_Shared_Date::isDateTime($cellobj)) {
    //it's a date
} 



回答2:


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



来源:https://stackoverflow.com/questions/41956979/how-to-check-the-date-type-in-array-in-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!