PHP Doku:: Creates new DatePeriod object - dateperiod.construct.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDatums- und zeitrelevante ErweiterungenDatum und UhrzeitThe DatePeriod classDatePeriod::__construct

Ein Service von Reinhard Neidl - Webprogrammierung.

The DatePeriod class

<<The DatePeriod class

Datum/Uhrzeit Funktionen>>

DatePeriod::__construct

(PHP 5 >= 5.3.0)

DatePeriod::__constructCreates new DatePeriod object

Beschreibung

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 ] )

Creates new DatePeriod object.

Parameter-Liste

start

Start date.

interval

Interval.

recurrences

Number of recurrences.

end

End date.

isostr

String containing the ISO interval.

options

Can be set to DatePeriod::EXCLUDE_START_DATE.


Ein BenutzerBeitrag:
- Beiträge aktualisieren...
simon dot kohlmeyer at mayflower dot de
3.11.2010 12: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



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)