reference/datetime/datetime/add.xml
02ff7fef5b34cf8f5395180d9d39fb64d9398d00
...
...
@@ -1,33 +1,40 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="datetime.add" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>DateTime::add</refname>
7
6
<refname>date_add</refname>
8
7
<refpurpose>
9
-
Adds an amount of days, months, years, hours, minutes and seconds to a
10
-
DateTime object
8
+
Modifies a DateTime object, with added amount of days, months, years, hours, minutes and seconds
11
9
</refpurpose>
12
10
</refnamediv>
13
11

14
12
<refsect1 role="description">
15
13
&reftitle.description;
16
14
<para>&style.oop;</para>
17
-
<methodsynopsis role="oop">
15
+
<methodsynopsis role="DateTime">
18
16
<modifier>public</modifier> <type>DateTime</type><methodname>DateTime::add</methodname>
19
17
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
20
18
</methodsynopsis>
21
19
<para>&style.procedural;</para>
22
-
<methodsynopsis role="procedural">
20
+
<methodsynopsis>
23
21
<type>DateTime</type><methodname>date_add</methodname>
24
22
<methodparam><type>DateTime</type><parameter>object</parameter></methodparam>
25
23
<methodparam><type>DateInterval</type><parameter>interval</parameter></methodparam>
26
24
</methodsynopsis>
25
+

27
26
<para>
28
27
Adds the specified <classname>DateInterval</classname> object to the
29
28
specified <classname>DateTime</classname> object.
30
29
</para>
30
+
<para>
31
+
Like <methodname>DateTimeImmutable::add</methodname> but works with
32
+
<classname>DateTime</classname>.
33
+
</para>
34
+
<para>
35
+
The procedural version takes the <classname>DateTime</classname> object as
36
+
its first argument.
37
+
</para>
31
38
</refsect1>
32
39

33
40
<refsect1 role="parameters">
...
...
@@ -50,109 +57,18 @@
50
57
<refsect1 role="returnvalues">
51
58
&reftitle.returnvalues;
52
59
<para>
53
-
&date.datetime.return.modifiedobjectorfalseforfailure;
54
-
</para>
55
-
</refsect1>
56
-

57
-
<refsect1 role="examples">
58
-
&reftitle.examples;
59
-
<example>
60
-
<title><function>DateTime::add</function> example</title>
61
-
<para>&style.oop;</para>
62
-
<programlisting role="php">
63
-
<![CDATA[
64
-
<?php
65
-
$date = new DateTime('2000-01-01');
66
-
$date->add(new DateInterval('P10D'));
67
-
echo $date->format('Y-m-d') . "\n";
68
-
?>
69
-
]]>
70
-
</programlisting>
71
-
<para>&style.procedural;</para>
72
-
<programlisting role="php">
73
-
<![CDATA[
74
-
<?php
75
-
$date = date_create('2000-01-01');
76
-
date_add($date, date_interval_create_from_date_string('10 days'));
77
-
echo date_format($date, 'Y-m-d');
78
-
?>
79
-
]]>
80
-
</programlisting>
81
-
&examples.outputs;
82
-
<screen>
83
-
<![CDATA[
84
-
2000-01-11
85
-
]]>
86
-
</screen>
87
-
</example>
88
-
<example>
89
-
<title>Further <function>DateTime::add</function> examples</title>
90
-
<programlisting role="php">
91
-
<![CDATA[
92
-
<?php
93
-
$date = new DateTime('2000-01-01');
94
-
$date->add(new DateInterval('PT10H30S'));
95
-
echo $date->format('Y-m-d H:i:s') . "\n";
96
-

97
-
$date = new DateTime('2000-01-01');
98
-
$date->add(new DateInterval('P7Y5M4DT4H3M2S'));
99
-
echo $date->format('Y-m-d H:i:s') . "\n";
100
-
?>
101
-
]]>
102
-
</programlisting>
103
-
&example.outputs;
104
-
<screen>
105
-
<![CDATA[
106
-
2000-01-01 10:00:30
107
-
2007-06-05 04:03:02
108
-
]]>
109
-
</screen>
110
-
</example>
111
-
<example>
112
-
<title>Beware when adding months</title>
113
-
<programlisting role="php">
114
-
<![CDATA[
115
-
<?php
116
-
$date = new DateTime('2000-12-31');
117
-
$interval = new DateInterval('P1M');
118
-

119
-
$date->add($interval);
120
-
echo $date->format('Y-m-d') . "\n";
121
-

122
-
$date->add($interval);
123
-
echo $date->format('Y-m-d') . "\n";
124
-
?>
125
-
]]>
126
-
</programlisting>
127
-
&example.outputs;
128
-
<screen>
129
-
<![CDATA[
130
-
2001-01-31
131
-
2001-03-03
132
-
]]>
133
-
</screen>
134
-
</example>
135
-
</refsect1>
136
-

137
-
<refsect1 role="notes">
138
-
&reftitle.notes;
139
-
<para>
140
-
<function>DateTime::modify</function>
141
-
is an alternative when using PHP 5.2.
60
+
&date.datetime.return.modifiedobject;
142
61
</para>
143
62
</refsect1>
144
63

145
64
<refsect1 role="seealso">
146
65
&reftitle.seealso;
147
66
<simplelist>
148
-
<member><function>DateTime::sub</function></member>
149
-
<member><function>DateTime::diff</function></member>
150
-
<member><function>DateTime::modify</function></member>
67
+
<member><function>DateTimeImmutable::add</function></member>
151
68
</simplelist>
152
69
</refsect1>
153
70

154
71
</refentry>
155
-

156
72
<!-- Keep this comment at the end of the file
157
73
Local variables:
158
74
mode: sgml
159
75