라이브러리
[PHP] DatePeriod::getStartDate - 시작 날짜를 가져옵니다.
DatePeriod::getStartDate
PHP 8.1 버전부터 DatePeriod 클래스가 추가되었으며, DatePeriod::getStartDate 메서드는 DatePeriod 객체의 시작 날짜를 반환합니다.
# 사용법
DatePeriod::getStartDate 메서드는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
php
$startDate = new DateTime('2022-01-01');
$endDate = new DateTime('2022-01-31');
$datePeriod = new DatePeriod(
new DateInterval('P1D'),
new DateInterval('P1D'),
$startDate,
new DatePeriodIteratorBoundary($endDate)
);
$startDate = $datePeriod->getStartDate();
echo $startDate->format('Y-m-d'); // 2022-01-01
# 예제
다음 예제에서는 DatePeriod::getStartDate 메서드를 사용하여 2022년 1월 1일부터 2022년 1월 31일까지의 날짜 범위를 생성하고, 시작 날짜를 출력합니다.
#hostingforum.kr
php
$startDate = new DateTime('2022-01-01');
$endDate = new DateTime('2022-01-31');
$datePeriod = new DatePeriod(
new DateInterval('P1D'),
new DateInterval('P1D'),
$startDate,
new DatePeriodIteratorBoundary($endDate)
);
$startDate = $datePeriod->getStartDate();
echo "시작 날짜: " . $startDate->format('Y-m-d') . "
";
foreach ($datePeriod as $date) {
echo $date->format('Y-m-d') . "
";
}
# 결과
시작 날짜: 2022-01-01
2022-01-01
2022-01-02
2022-01-03
...
2022-01-31
# 참고
DatePeriod::getStartDate 메서드는 DatePeriod 객체의 시작 날짜를 반환합니다. 이 메서드는 DatePeriod 객체를 생성할 때 사용할 수 있으며, 시작 날짜를 확인하거나 날짜 범위의 시작점을 지정할 때 유용합니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.