如何在PHP中检查数组中的日期类型 [英] How to check the date type in array in PHP

查看:131
本文介绍了如何在PHP中检查数组中的日期类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHPExcel读取数据,然后验证数据.我得到的问题是所有数据都在验证,除了我不知道如何检查数组是否有日期.问题不是格式,问题是我无法找到一种检查日期还是其他字符串或整数的方法.这些是我在Excel文件中日期单元格中的值之一.即;

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

推荐答案

您必须检查当前的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

这篇关于如何在PHP中检查数组中的日期类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆