<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'fr',
  ),
  'this' => 
  array (
    0 => 'datetime.modify.php',
    1 => 'DateTime::modify',
    2 => 'Modifie le timestamp',
  ),
  'up' => 
  array (
    0 => 'class.datetime.php',
    1 => 'DateTime',
  ),
  'prev' => 
  array (
    0 => 'datetime.getlasterrors.php',
    1 => 'DateTime::getLastErrors',
  ),
  'next' => 
  array (
    0 => 'datetime.set-state.php',
    1 => 'DateTime::__set_state',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/datetime/datetime/modify.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="datetime.modify" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTime::modify</h1>
  <h1 class="refname">date_modify</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTime::modify</span> -- <span class="refname">date_modify</span> &mdash; <span class="dc-title">Modifie le timestamp</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-datetime.modify-description">
  <h3 class="title">Description</h3>
  <p class="para">Style orienté objet</p>
  <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><strong>DateTime::modify</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$modifier</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>

  <p class="para rdfs-comment">Style procédural</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><a href="function.date-modify.php" class="methodname">date_modify</a></span>(<span class="methodparam"><span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$modifier</code></span>): <span class="type"><span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Modifie le timestamp d&#039;un objet <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span> 
   en l&#039;incrémentant ou le décrémentant
   dans un format acceptable par <span class="function"><a href="datetimeimmutable.construct.php" class="function">DateTimeImmutable::__construct()</a></span>.
  </p>
 </div>

 
 <div class="refsect1 parameters" id="refsect1-datetime.modify-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   <dt><code class="parameter">object</code></dt>
<dd><p class="para">Style procédural uniquement : Un objet <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span>
    retourné par la fonction <span class="function"><a href="function.date-create.php" class="function">date_create()</a></span>.
    Cette fonction modifie cet objet.</p></dd>
   
    <dt><code class="parameter">modifier</code></dt>
    <dd>
     <p class="para">Une chaîne date/heure. Les formats valides sont expliqués dans la documentation sur les
<a href="datetime.formats.php" class="link">formats Date et Heure</a>.</p>
    </dd>
   
  </dl>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-datetime.modify-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span> en cas de succès.
   Style procédural retourne <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en cas d&#039;erreur.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-datetime.modify-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
   API orientée objet uniquement :
   Si une chaîne de date ou de temps invalide est fournie, une
   <span class="exceptionname"><a href="class.datemalformedstringexception.php" class="exceptionname">DateMalformedStringException</a></span> est lancée.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetime.modify-changelog">
  <h3 class="title">Historique</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       <span class="methodname"><strong>DateTime::modify()</strong></span> lance désormais
       <span class="exceptionname"><a href="class.datemalformedstringexception.php" class="exceptionname">DateMalformedStringException</a></span> si une
       chaîne invalide est passée. Auparavant, il retournait <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>,
       et un avertissement était émis.
       <span class="function"><a href="function.date-modify.php" class="function">date_modify()</a></span> n&#039;a pas été modifiée.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>

 
 <div class="refsect1 examples" id="refsect1-datetime.modify-examples">
  <h3 class="title">Exemples</h3>
  <div class="example" id="example-1">
   <p><strong>Exemple #1 Exemple avec <span class="function"><strong>DateTime::modify()</strong></span></strong></p>
   <div class="example-contents"><p>Style orienté objet</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">'2006-12-12'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 day'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">);</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">2006-12-13</pre>
</div>
   </div>
   <div class="example-contents"><p>Style procédural</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #0000BB">date_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'2006-12-12'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">date_modify</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">, </span><span style="color: #DD0000">'+1 day'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">date_format</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">, </span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">);</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">2006-12-13</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-2">
   <p><strong>Exemple #2 Il faut se méfier lors de l&#039;ajout ou la soustraction de mois</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">'2000-12-31'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 month'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'+1 month'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">2001-01-31
2001-03-03</pre>
</div>
   </div>
  </div>
  <div class="example" id="example-3">
   <p><strong>Exemple #3 Tous les formats de date et d&#039;heure sont pris en charge</strong></p>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?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">'2020-12-31'</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'July 1st, 2023'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d H:i'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'Monday next week'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d H:i'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">modify</span><span style="color: #007700">(</span><span style="color: #DD0000">'17:30'</span><span style="color: #007700">);<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Y-m-d H:i'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</span></span></code></div>
   </div>

   <div class="example-contents"><p>L&#039;exemple ci-dessus va afficher :</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">2023-07-01 00:00
2023-07-03 00:00
2023-07-03 17:30</pre>
</div>
   </div>
  </div>
 </div>

 
 <div class="refsect1 seealso" id="refsect1-datetime.modify-seealso">
  <h3 class="title">Voir aussi</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="function.strtotime.php" class="function" rel="rdfs-seeAlso">strtotime()</a> - Transforme un texte anglais en timestamp</span></li>
   <li><span class="function"><a href="datetimeimmutable.modify.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::modify()</a> - Cr&eacute;e un nouvel objet avec l'horodatage modifi&eacute;</span></li>
   <li><span class="function"><a href="datetime.add.php" class="function" rel="rdfs-seeAlso">DateTime::add()</a> - Modifie un objet DateTime, avec le nombre de jours, mois, ann&eacute;es, heures, minutes et secondes ajout&eacute;</span></li>
   <li><span class="function"><a href="datetime.sub.php" class="function" rel="rdfs-seeAlso">DateTime::sub()</a> - Soustrait une dur&eacute;e &agrave; un objet DateTime</span></li>
   <li><span class="function"><a href="datetime.setdate.php" class="function" rel="rdfs-seeAlso">DateTime::setDate()</a> - Assigne la date</span></li>
   <li><span class="function"><a href="datetime.setisodate.php" class="function" rel="rdfs-seeAlso">DateTime::setISODate()</a> - Configure une date ISO</span></li>
   <li><span class="function"><a href="datetime.settime.php" class="function" rel="rdfs-seeAlso">DateTime::setTime()</a> - Assigne l'heure</span></li>
   <li><span class="function"><a href="datetime.settimestamp.php" class="function" rel="rdfs-seeAlso">DateTime::setTimestamp()</a> - Assigne la date et l'heure &agrave; l'aide d'un horodatage Unix</span></li>
  </ul>
 </div>

 
</div><?php manual_footer($setup); ?>