728x90

PHP 에서 특정 날짜를 구하는 예제이다.

<?php
ini_set("display_startup_errors", 1);
ini_set("display_errors", 1);
error_reporting(E_ALL);

$today = date("Y-m-d");
$end_date = date('Y-m-d', strtotime('-1 day'));

echo $today.'<br/>';
echo $end_date.'<br/>';

date("Y-m-d H:i:s", strtotime("-1 day")); // 어제 
date("Y-m-d H:i:s", strtotime("now")); // 현재 
date("Y-m-d H:i:s", strtotime("+1 day")); // 내일 
date("Y-m-d H:i:s", strtotime("+1 week")); // 일주일 후 
date("Y-m-d H:i:s", strtotime("-1 month")); // 한달 전 
date("Y-m-d H:i:s", strtotime("+1 month")); // 다음달 
date("Y-m-d H:i:s", strtotime("+1 week 2 days 3 hours 4 seconds")); // 1주 2일 3시간 4초 후 
date("Y-m-d H:i:s", strtotime("next Thursday")); // 다음주 목요일 
date("Y-m-d H:i:s", strtotime("last Monday")); // 지난 월요일

$date = "2021-04-01";
$today = date('Y-m-d', strtotime($date));
$end_date = date('Y-m-d', strtotime($date.' -1 day'));
$c_date =  date("Y-m-d H:i:s", strtotime($date. ' + 3 days'));

echo $today.'<br/>';
echo $end_date.'<br/>';
echo $c_date;
?>
블로그 이미지

Link2Me

,