나는 유효성 검사 오류 php를 사용하여 날짜 범위를 비교하여 날짜 범위를 확인하는 방법은 무엇입니까?
- 체크 아웃 날짜가 날짜 확인보다 오래된 경우을 보여주고 싶어요.
- 체크인 날짜가 오늘 내일 또는 내일 이후 일 경우 오류 메시지를 추가하십시오. 체크인 및 체크 아웃 날짜가 같으면
- 입니다.
- 체크 아웃 날짜가 적어도 체크인 날짜보다 늦지 않은 경우.
이러한 목적을 위해 몇 가지 변수를 만들었습니다.
$checkin_booking_period = $_POST["checkin_booking_period"];
$checkout_booking_period = $_POST["checkout_booking_period"];
$today = date("m.d.y");
$dateTimestamp1 = strtotime($checkin_booking_period);
$dateTimestamp2 = strtotime($checkout_booking_period);
$tomorrow = mktime(0, 0, 0, date("m"), date("d")+1, date("y"));
$day_after_tomorrow = mktime(0, 0, 0, date("m"), date("d")+2, date("y"));
내 조건 문은 다음과 같습니다
가//check out date must be newer than check in date.
if ($dateTimestamp1 > $dateTimestamp2) {
//Blank string, add error to $errors array.
$errors['checkout_booking_period'] = "check out date must be newer than check in date!";
}
if (($dateTimestamp1 = $tomorrow) || ($dateTimestamp1 = $day_after_tomorrow) || ($dateTimestamp1 = $today)) {
// if checkin date is equal to today tomorrow or day after tomorrow add error message
$errors['checkout_booking_period'] = "You have to reserve the place at least two days before the check in!";
}
if ($dateTimestamp1 = $dateTimestamp2) {
$errors['checkout_booking_period'] = "check in date and check out date can not be same!";
}
하지만, 이러한 조건 문이 전체 요구 사항을 기입하지 않습니다. 예 : 체크인이 과거이고 체크 아웃 예정일 인 경우 "체크인 날짜와 체크 아웃 날짜는 같을 수 없습니다!" 위에서 언급 한 요구 사항을 모두 충족하는 조건문을 만드는 방법은 무엇입니까?
1 :
데이터베이스에서이 날짜를 반환하는 경우 DB – mwafi