에포크 타임 스탬프 형식으로 datetime을 저장하는 동안 MySQL 날짜/시간 함수를 사용하는 솔루션이 매우 느릴 수 있다고 생각합니다. 그래서 아래의 코드처럼 타임 스탬프 자체를 사용하는 것이 좋습니다.
사용 예 쿼리에서
$t = time();
# today
echo date('Y-m-d H:i:s', strtotime('today', $t))."\n";
echo date('Y-m-d H:i:s', strtotime('tomorrow', $t))."\n";
# this week
echo date('Y-m-d H:i:s', strtotime('-1 sunday', $t))."\n";
echo date('Y-m-d H:i:s', strtotime('sunday', $t))."\n";
# this month
echo date('Y-m-d H:i:s', strtotime(date('Y-m-01 00:00:00', $t)))."\n";
echo date('Y-m-d H:i:s', strtotime(date('Y-m-01 00:00:00', strtotime('next month', $t))))."\n";
# this year
echo date('Y-m-d H:i:s', strtotime(date('Y-01-01 00:00:00', $t)))."\n";
echo date('Y-m-d H:i:s', strtotime(date('Y-01-01 00:00:00', strtotime('next year', $t))))."\n";
# this year
$start_of_year = strtotime(date('Y-01-01 00:00:00', $t));
$end_of_year = strtotime(date('Y-01-01 00:00:00', strtotime('next year', $t)));
$query = "SELECT * FROM sometable WHERE somecolumn >= $start_of_year AND somecolumn < $end_of_year";
쉽게) (PHP의 날짜 등이 날의 타임 스탬프, 주를 시작 계산할 수
/한 strtotime() 함수는, 예를 들어 시작 시간 오늘 : strtotime (날짜 ("Ymd")) 등 – XzKto