PHP, Codeigniter
php 실제 존재하는 날짜 체크
beop07
2021. 5. 21. 09:28
php 존재하는 날짜인지 체크하는 방법입니다.
checkdate()
checkdate("월", "일", "년"); // return boolean
function checkDate($date){
$dateArr = explode('-', $date);
$year = $dateArr[0];
$month = $dateArr[1];
$days = $dateArr[2];
return checkdate($month, $days, $year);
}
$newDate = "2021-02-31";
$check = checkDate($newDate);
// $check -> FALSE
문자열 형태로 넘겨서 explode로 쪼갠후 넘겼는데 이유는
date("y-m-d" ,strtotime("2021-02-31")); 나 new DateTime()->format() 을 사용하면 해당 날짜를 다음 월의 1일로 변환해주기때문에 정확한 값을 얻을 수 없다.
keywords : php 존재하는 날짜 체크, php 실제 날짜 확인, php 존재하는 날짜 확인, php date check, php get real date
반응형