개발 스크랩 메모/PHP
PHP 는 날짜와 시간을 비교해서 [중복]
렉사이
2020. 12. 25. 02:37
This question already has an answer here:
- comparing date and time php 2 answers
나는 세 번 데이트한 A, B 와 C 가 있다.
A = 2013-08-10 10:00 B = 2013-08-10 12:00 C = 2013-08-10 10:22
C 가 A 와 B 에서 되돌아올지 여부를 확인하는 것이다.
어떻게 하는지 아시는 분?
저는 운이 없어서 해봤어요.
if ($time >= $date_start && $time <= $date_end) { echo "is between\n"; } else { echo 'no'; }
대답
UNIX 시간 스탬프를 비교할 수 있습니다.
$A = strtotime($A); //gives value in Unix Timestamp (seconds since 1970) $B = strtotime($B); $C = strtotime($C); if ((($C < $A) && ($C > $B)) || (($C > $A) && ($C < $B)) ){ echo "Yes '$C' is between '$A' and '$B'"; }