<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>The DateTimeImmutable class</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetime.sub.html">DateTime::sub</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetimeimmutable.add.html">DateTimeImmutable::add</a></div> <div class="up"><a href="book.datetime.html">Date/Time</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="class.datetimeimmutable" class="reference"> <h1 class="title">The DateTimeImmutable class</h1> <div class="partintro"><p class="verinfo">(PHP 5 >= 5.5.0)</p> <div class="section" id="datetimeimmutable.intro"> <h2 class="title">Introduction</h2> <p class="para"> This class behaves the same as <a href="class.datetime.html" class="classname">DateTime</a> except it never modifies itself but returns a new object instead. </p> </div> <div class="section" id="datetimeimmutable.synopsis"> <h2 class="title">Class synopsis</h2> <div class="classsynopsis"> <div class="ooclass"></div> <div class="classsynopsisinfo"> <span class="ooclass"> <strong class="classname">DateTimeImmutable</strong> </span> <span class="oointerface">implements <span class="interfacename"><a href="class.datetimeinterface.html" class="interfacename">DateTimeInterface</a></span> </span> {</div> <div class="classsynopsisinfo classsynopsisinfo_comment">/* Methods */</div> <div class="constructorsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><a href="datetimeimmutable.construct.html" class="methodname">__construct</a></span> ([ <span class="methodparam"><span class="type">string</span> <code class="parameter">$time</code><span class="initializer"> = "now"</span></span> [, <span class="methodparam"><span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$timezone</code><span class="initializer"> = <strong><code>NULL</code></strong></span></span> ]] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.add.html" class="methodname">add</a></span> ( <span class="methodparam"><span class="type"><a href="class.dateinterval.html" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.createfromformat.html" class="methodname">createFromFormat</a></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span> , <span class="methodparam"><span class="type">string</span> <code class="parameter">$time</code></span> [, <span class="methodparam"><span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$timezone</code></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">array</span> <span class="methodname"><a href="datetimeimmutable.getlasterrors.html" class="methodname">getLastErrors</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.modify.html" class="methodname">modify</a></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$modify</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.set-state.html" class="methodname">__set_state</a></span> ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$array</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.setdate.html" class="methodname">setDate</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$year</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$month</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$day</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.setisodate.html" class="methodname">setISODate</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$year</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$week</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$day</code><span class="initializer"> = 1</span></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.settime.html" class="methodname">setTime</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$hour</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$minute</code></span> [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$second</code><span class="initializer"> = 0</span></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.settimestamp.html" class="methodname">setTimestamp</a></span> ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$unixtimestamp</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.settimezone.html" class="methodname">setTimezone</a></span> ( <span class="methodparam"><span class="type"><a href="class.datetimezone.html" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$timezone</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeImmutable</span> <span class="methodname"><a href="datetimeimmutable.sub.html" class="methodname">sub</a></span> ( <span class="methodparam"><span class="type"><a href="class.dateinterval.html" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateInterval</span> <span class="methodname"><a href="datetime.diff.html" class="methodname">diff</a></span> ( <span class="methodparam"><span class="type"><a href="class.datetimeinterface.html" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$datetime2</code></span> [, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$absolute</code><span class="initializer"> = false</span></span> ] )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">string</span> <span class="methodname"><a href="datetime.format.html" class="methodname">format</a></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><a href="datetime.getoffset.html" class="methodname">getOffset</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><a href="datetime.gettimestamp.html" class="methodname">getTimestamp</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type">DateTimeZone</span> <span class="methodname"><a href="datetime.gettimezone.html" class="methodname">getTimezone</a></span> ( <span class="methodparam">void</span> )</div> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="methodname"><a href="datetime.wakeup.html" class="methodname">__wakeup</a></span> ( <span class="methodparam">void</span> )</div> }</div> </div> </div> <h2>Table of Contents</h2><ul class="chunklist chunklist_reference"><li><a href="datetimeimmutable.add.html">DateTimeImmutable::add</a> — Adds an amount of days, months, years, hours, minutes and seconds</li><li><a href="datetimeimmutable.construct.html">DateTimeImmutable::__construct</a> — Returns new DateTimeImmutable object</li><li><a href="datetimeimmutable.createfromformat.html">DateTimeImmutable::createFromFormat</a> — Returns new DateTimeImmutable object formatted according to the specified format</li><li><a href="datetimeimmutable.getlasterrors.html">DateTimeImmutable::getLastErrors</a> — Returns the warnings and errors</li><li><a href="datetimeimmutable.modify.html">DateTimeImmutable::modify</a> — Alters the timestamp</li><li><a href="datetimeimmutable.set-state.html">DateTimeImmutable::__set_state</a> — The __set_state handler</li><li><a href="datetimeimmutable.setdate.html">DateTimeImmutable::setDate</a> — Sets the date</li><li><a href="datetimeimmutable.setisodate.html">DateTimeImmutable::setISODate</a> — Sets the ISO date</li><li><a href="datetimeimmutable.settime.html">DateTimeImmutable::setTime</a> — Sets the time</li><li><a href="datetimeimmutable.settimestamp.html">DateTimeImmutable::setTimestamp</a> — Sets the date and time based on an Unix timestamp</li><li><a href="datetimeimmutable.settimezone.html">DateTimeImmutable::setTimezone</a> — Sets the time zone</li><li><a href="datetimeimmutable.sub.html">DateTimeImmutable::sub</a> — Subtracts an amount of days, months, years, hours, minutes and seconds</li></ul> </div> <hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetime.sub.html">DateTime::sub</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetimeimmutable.add.html">DateTimeImmutable::add</a></div> <div class="up"><a href="book.datetime.html">Date/Time</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>