Ví dụ về DatePeriod PHP

Sử dụng hằng số

 $exclude = DatePeriod::EXCLUDE_START_DATE;
 $period = new DatePeriod($date, $interval, $occurences, $exclude);

 foreach ($period as $date) {
  echo '['. $date->format('d-M-Y') . '] ';
 }
 # [27-Apr-2022] [27-Jul-2022] [27-Oct-2022]
3 trong tham số thứ 4 của hàm tạo DatePeriod để loại trừ kết quả đầu tiên

This class isn't always intuitive. End is exclusive. All you need to do to include it is to add a second (the smallest amount).

Microseconds are ignored.

php -r '
/***/$p1d = new DateInterval("P1D");
/***/$b = (new DateTime())->setTime(0, 0, 0, 0);
/***/$a = (clone $b)->sub($p1d);

/***/$f = function(DateTime $b)use($a, $p1d):void {
/***//***/$p = new DatePeriod($a, $p1d, $b);
/***//***/$i = iterator_to_array($p);
/***//***/print_r([$i[0], end($i), $a, $b]);
/***/};

/***/$f($b);
/***/$f($b->setTime(0, 0, 0, 1));
/***/$f($b->setTime(0, 0, 1, 0));
'

It is a sign of the end times.

When looping over a DatePeriod object, the returned objects always implement DateTimeInterface. The exact type returned depends on how the DatePeriod was created. If $start was a DateTimeImmutable, the objects returned will be of type DateTimeImmutable. If a DateTime object was used, the objects returned will be of type DateTime.

Làm cách nào để kiểm tra ngày giữa hai ngày trong php?

hàm php displayDates($date1, $date2, $format = 'd-m-Y' ) { $dates = array();

Làm cách nào để đặt phạm vi ngày trong php?

rarst. net/code/php-date-range HOẶC boonedocks. net/blog/2007/01/08/… – Anant - Sống để chết. .
Vì vậy, +1 tháng sẽ thêm 30 ngày tiếp theo hoặc bao nhiêu ngày trong ngày cơ sở? . .
sử dụng dateperiod $period = new DatePeriod($date, new DateInterval('P1D'), $end_date); . .
Bản sao có thể có của Phạm vi ngày PHP, Mảng

Khoảng thời gian là gì?

NG NGÀY CÓ KINH CUỐI CÙNG là ngày đầu tiên của kỳ kinh cuối cùng của MỘT NGƯỜI .

Làm cách nào để có được ngày kết thúc trong php?

php // 👇 lấy dấu thời gian của ngày $date = strtotime("2nd January 2022"); . $last_date = date("Y-m-t", $date); print $last_date; // 2022-01-31 // 👇 convert last date to timestamp again $last_date = strtotime($last_date); // 👇 get the day of the last date $last_day = date("l", $ ...