PHP过去时间验证
我在PHP上验证$input的时间时遇到了一个问题。 我的输入值为 年-月-日hh:mm下午/上午 如果所选日期已过或今天,则会出现错误。我该怎么做 任何帮助都是一种感激。谢谢。是你的朋友PHP过去时间验证,php,Php,我在PHP上验证$input的时间时遇到了一个问题。 我的输入值为 年-月-日hh:mm下午/上午 如果所选日期已过或今天,则会出现错误。我该怎么做 任何帮助都是一种感激。谢谢。是你的朋友 $input = '2012-06-07 01:23 PM'; if(strtotime($input) < time()){ echo "error"; } $input='2012-06-07 01:23 PM'; if(strotime($input)$今天){ #要执行的代码放在这里
$input = '2012-06-07 01:23 PM';
if(strtotime($input) < time()){
echo "error";
}
$input='2012-06-07 01:23 PM';
if(strotime($input)
你说的是今天,所以我想你不是指当前时间,而是指当前日期
<?php
$input = strtotime( '2012-06-07 01:23 PM' );
if ( date( 'Y-m-d', $input ) == date( 'Y-m-d' ) || $input > time() ) {
echo 'ERROR';
}
$today=标准时间($todays\u date);
$expiration\u date=strottime($input);
如果($到期日>$今天){
#要执行的代码放在这里
}
或使用
$d1=新日期时间(“现在”);
$d2=新日期时间($input);
#使用PHP的关系运算符来比较两者。
在PHP中,您可以使用以下方法进行检查:
$input_date_time = strtotime( 'your input date here' );
$input_date = strtotime(date( 'Y-m-d', $input_date_time ));
$current_date = strtotime(date( 'Y-m-d',time()));
if ($input_date_time < time () || $input_date == $current_date) {
echo "error here";
}
$input\u date\u time=strottime(“此处输入日期”);
$input_date=STROTIME(日期('Y-m-d',$input_date_time));
$current_date=strottime(日期('Y-m-d',time());
如果($input_date_time
您还可以使用jQuery日期时间选择器。如果您使用的是jQuery日期时间选择器,则有一个选项可以防止选择当前日期或所需日期之前的日期
希望这有帮助我不认为yy-mm-dd
是一种有效的日期格式。你自己尝试过吗?这个问题即使用最少量的基本搜索也很难解决。所以这里不是“为我编写代码”资源。你试过什么吗?看一看strotimefunction@Rocket我刚刚尝试了示例字符串03-10-10 10:12 PM
,并且strotime()
给了我一个纪元(虽然不一定是正确的)。date(“c”,strotime(“03-10-10 10:12 PM”)
这里是“2003-10-10T22:12:00+02:00”
,我的strotime
版本的格式没有问题。为了安全起见,我们可以使用DateTIme::createFromFormat()
。@Wrikken:我有点诵读困难:-P“过去还是今天”。。。所以
$d1 = new DateTime("now");
$d2 = new DateTime($input);
#Use PHP's relational operators to compare the two.
$input_date_time = strtotime( 'your input date here' );
$input_date = strtotime(date( 'Y-m-d', $input_date_time ));
$current_date = strtotime(date( 'Y-m-d',time()));
if ($input_date_time < time () || $input_date == $current_date) {
echo "error here";
}