我有一個問題,在這裏驗證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