且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在PHP中检查数组中的日期类型

更新时间:2023-11-26 11:16:22

您必须检查当前的PHP版本,因为新功能在旧版本中不可用.您的日期格式是否固定?如果是,则存在函数checkdate ().,它将在有效日期返回true.

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.

我的建议是,explode() 1/2/15 17:24来自excel的数据,然后将其传递给checkdate()函数,如果返回true,则为"DATE"或整个excel列包含DATE

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