date_modify

(PHP 5 >= 5.2.0, PHP 7)

date_modifyПсевдоним DateTime::modify()

Описание

Эта функция является псевдонимом: DateTime::modify()

Коментарии

Автор:
I decided to enhance the DateTime object by taking advantage of method chaining.

<?php

class DateTimeChain extends DateTime {

    public function 
modify ($modify) {
       
parent::modify($modify);
        return 
$this;
    }

    public function 
setDate ($year$month$day) {
       
parent::setDate($year$month$day);
        return 
$this;
    }

    public function 
setISODate ($year$week$day null) {
       
parent:: setISODate($year$week$day);
        return 
$this;
    }

    public function 
setTime ($hour$minute$second null) {
       
parent::setTime($hour$minute$second);
        return 
$this;
    }

    public function 
setTimezone ($timezone) {
       
parent::setTimezone($timezone);
        return 
$this;
    }

}

$t = new DateTimeZone('America/Los_Angeles');
$d = new DateTimeChain();
var_dump($d->setTimezone($t)->modify('5years')->format(DATE_RFC822));

?>
2007-09-15 02:46:58
http://php5.kiev.ua/manual/ru/function.date-modify.html
I have trouble finding the documentation for the dateTime object, but this seems to work:

<?php
$currentDate 
= new DateTime('2008-01-04');
$endDate     = new DateTime('2009-01-04');

while(
$currentDate $endDate) {
  echo 
$currentDate -> format('Y-m-d') . ' till '
 
$currentDate      -> modify('+1 week');
  echo 
$currentDate -> format('Y-m-d') . ' <br />';
}
?>

This will (obviously) print a list of date-ranges between startdate and enddate.
2007-12-08 06:38:44
http://php5.kiev.ua/manual/ru/function.date-modify.html
$cday - specified day of the week (0-6 where 0 is Sunday)
$currentDate - date of start
$endDate - date of end

We need dates of next couple of days, that day of week  match defined.

<?php

           
if($currentDate->format('w')!= $cday){
            switch (
$cday){ 
            case 
$cdays="Sunday"; break;
            case 
$cdays="Monday"; break;
            case 
$cdays="Tuesday"; break;
            case 
$cdays="Wednesday"; break;
            case 
$cdays="Thursday"; break;
            case 
$cdays="Friday"; break;
            case 
$cdays="Saturday";
            }   
           
date_modify($currentDate,"+1 {$cdays}");
            }
           
   
            while(
$currentDate $endDate) {
              echo 
$currentDate -> format('Y-m-d H:i:s');
             
$currentDate      -> modify('+1 week');
            }

?>
2008-08-14 08:49:49
http://php5.kiev.ua/manual/ru/function.date-modify.html

    Поддержать сайт на родительском проекте КГБ