downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Fonctions Date/Heure> <DatePeriod
[edit] Last updated: Fri, 25 May 2012

view this page in

DatePeriod::__construct

(PHP 5 >= 5.3.0)

DatePeriod::__constructCrée un nouvel objet DatePeriod

Description

public DatePeriod::__construct() ( DateTime $start , DateInterval $interval , int $recurrences [, int $options ] )
public DatePeriod::__construct() ( DateTime $start , DateInterval $interval , DateTime $end [, int $options ] )
public DatePeriod::__construct() ( string $isostr [, int $options ] )

Crée un nouvel objet DatePeriod.

Liste de paramètres

start

Date de début.

interval

Intervalle.

recurrences

Nombre de récurrences.

end

Date de fin.

isostr

Chaîne contenant l'intervalle ISO.

options

Peut être configuré à DatePeriod::EXCLUDE_START_DATE.



add a note add a note User Contributed Notes DatePeriod::__construct
simon dot kohlmeyer at mayflower dot de 03-Nov-2010 03:50
I found two things useful to know that aren't covered here.

1. endDate is excluded:

<?php
$i
= new DateInterval('P1D');
$d1 = new Datetime();
$d2 = clone $d1; $d2->add($i);
foreach(new
DatePeriod($d1, $i, $d2) as $d) {
    echo
$d->format('Y-m-d H:i:s') . "\n";
}
?>

Will output:
2010-11-03 12:39:53

(Another one because I got it wrong at first)
2. For the first form, recurrences really means REcurrences, not occurences.

<?php
$i
= new DateInterval('P1D');
$d = new Datetime();
foreach(new
DatePeriod($d, $i, 1) as $d) {
    echo
$d->format('Y-m-d H:i:s') . "\n";
}
?>

Will output:
2010-11-03 12:41:05
2010-11-04 12:41:05

 
show source | credits | stats | sitemap | contact | advertising | mirror sites