1
0
mirror of https://github.com/php/doc-en.git synced 2026-03-24 07:42:10 +01:00
Files
Tim Düsterhus 42d5fb01e0 Update function attributes
Generated with:

     build/gen_stub.php --replace-methodsynopses **.stub.php ../phpdoc/en/

And then manually picked the changes.
2025-10-04 16:04:02 +02:00

143 lines
3.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="datetimeimmutable.add" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>DateTimeImmutable::add</refname>
<refpurpose>
Returns a new object, with added amount of days, months, years, hours, minutes and seconds
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis role="DateTimeImmutable">
<modifier role="attribute">#[\NoDiscard]</modifier>
<modifier>public</modifier> <type>DateTimeImmutable</type><methodname>DateTimeImmutable::add</methodname>
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
</methodsynopsis>
<para>
Creates a new <classname>DateTimeImmutable</classname> object, and adds the
specified <classname>DateInterval</classname> object to this, to represent
the new value.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
<varlistentry>
<term>
<parameter>interval</parameter>
</term>
<listitem>
<para>
A <classname>DateInterval</classname> object
</para>
</listitem>
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&date.datetimeimmutable.return.modifiedobject;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>DateTimeImmutable::add</function> example</title>
<para>&style.oop;</para>
<programlisting role="php">
<![CDATA[
<?php
$date = new DateTimeImmutable('2000-01-01');
$newDate = $date->add(new DateInterval('P10D'));
echo $newDate->format('Y-m-d') . "\n";
?>
]]>
</programlisting>
</example>
<example>
<title>Further <function>DateTimeImmutable::add</function> examples</title>
<programlisting role="php">
<![CDATA[
<?php
$date = new DateTimeImmutable('2000-01-01');
$newDate = $date->add(new DateInterval('PT10H30S'));
echo $newDate->format('Y-m-d H:i:s') . "\n";
$date = new DateTimeImmutable('2000-01-01');
$newDate = $date->add(new DateInterval('P7Y5M4DT4H3M2S'));
echo $newDate->format('Y-m-d H:i:s') . "\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2000-01-01 10:00:30
2007-06-05 04:03:02
]]>
</screen>
</example>
<example>
<title>Beware when adding months</title>
<programlisting role="php">
<![CDATA[
<?php
$date = new DateTimeImmutable('2000-12-31');
$interval = new DateInterval('P1M');
$newDate1 = $date->add($interval);
echo $newDate1->format('Y-m-d') . "\n";
$newDate2 = $newDate1->add($interval);
echo $newDate2->format('Y-m-d') . "\n";
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
2001-01-31
2001-03-03
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member><function>DateTimeImmutable::sub</function></member>
<member><function>DateTimeImmutable::diff</function></member>
<member><function>DateTimeImmutable::modify</function></member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->