<!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>Returns new DateTimeImmutable object encapsulating the given DateTime object</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetimeimmutable.createfromformat.html">DateTimeImmutable::createFromFormat</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetimeimmutable.getlasterrors.html">DateTimeImmutable::getLastErrors</a></div> <div class="up"><a href="class.datetimeimmutable.html">DateTimeImmutable</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="datetimeimmutable.createfrommutable" class="refentry"> <div class="refnamediv"> <h1 class="refname">DateTimeImmutable::createFromMutable</h1> <p class="verinfo">(PHP 5 >= 5.6.0, PHP 7)</p><p class="refpurpose"><span class="refname">DateTimeImmutable::createFromMutable</span> — <span class="dc-title">Returns new DateTimeImmutable object encapsulating the given DateTime object</span></p> </div> <div class="refsect1 description" id="refsect1-datetimeimmutable.createfrommutable-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="modifier">static</span> <span class="type"><a href="class.datetimeimmutable.html" class="type DateTimeImmutable">DateTimeImmutable</a></span> <span class="methodname"><strong>DateTimeImmutable::createFromMutable</strong></span> ( <span class="methodparam"><span class="type"><a href="class.datetime.html" class="type DateTime">DateTime</a></span> <code class="parameter">$datetime</code></span> )</div> </div> <div class="refsect1 parameters" id="refsect1-datetimeimmutable.createfrommutable-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <code class="parameter">datetime</code></dt> <dd> <p class="para"> The mutable <a href="class.datetime.html" class="classname">DateTime</a> object that you want to convert to an immutable version. This object is not modified, but instead a new <a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a> object is created containing the same date time and timezone information. </p> </dd> </dl> </p> </div> <div class="refsect1 examples" id="refsect1-datetimeimmutable.createfrommutable-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-2763"> <p><strong>Example #1 Creating an immutable date time object</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br />$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTime</span><span style="color: #007700">(</span><span style="color: #DD0000">"2014-06-20 11:45 Europe/London"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$immutable </span><span style="color: #007700">= </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">::</span><span style="color: #0000BB">createFromMutable</span><span style="color: #007700">( </span><span style="color: #0000BB">$date </span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 returnvalues" id="refsect1-datetimeimmutable.createfrommutable-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> Returns a new <a href="class.datetimeimmutable.html" class="classname">DateTimeImmutable</a> instance. </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="datetimeimmutable.createfromformat.html">DateTimeImmutable::createFromFormat</a></div> <div class="next" style="text-align: right; float: right;"><a href="datetimeimmutable.getlasterrors.html">DateTimeImmutable::getLastErrors</a></div> <div class="up"><a href="class.datetimeimmutable.html">DateTimeImmutable</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>