我有一个问题,在这里验证PHP的我的$输入的时间。 我的输入有PHP过去的时间验证
YY-MM-DD HH值:毫米PM/AM
如果选择的日期是过去还是今天,它会得到一个错误。我怎样才能做到这一点?
任何帮助是感谢。谢谢。
我有一个问题,在这里验证PHP的我的$输入的时间。 我的输入有PHP过去的时间验证
YY-MM-DD HH值:毫米PM/AM
如果选择的日期是过去还是今天,它会得到一个错误。我怎样才能做到这一点?
任何帮助是感谢。谢谢。
您今天说过,所以我假设您不是指当前时间,而是当前日期?
<?php
$input = strtotime('2012-06-07 01:23 PM');
if (date('Y-m-d', $input) == date('Y-m-d') || $input > time()) {
echo 'ERROR';
}
$today = strtotime($todays_date); $expiration_date = strtotime($input); if ($expiration_date > $today) { #Your code to be executed goes in here }
或使用DateTime
$d1 = new DateTime("now"); $d2 = new DateTime($input); #Use PHP's relational operators to compare the two.
在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";
}
您还可以使用jQuery日期时间选择器。如果您使用的是jQuery日期时间选择器,则可以选择防止在当前日期或所需日期之前选择日期。
希望这有助于
邮编...... –
我不认为'YY-MM-dd'是一个有效的日期格式。 –
你自己尝试过吗?即使是最基本的搜索,这个问题也很容易解决。因此,这里并不是“为我编码”的资源。 – Bojangles