reference/datetime/functions/strtotime.xml
5c951013ca04161992efed8b86fb40f55669958e
...
...
@@ -18,7 +18,10 @@
18
18
and will try to parse that format into a Unix timestamp (the number of
19
19
seconds since January 1 1970 00:00:00 UTC), relative to the timestamp given
20
20
in <parameter>baseTimestamp</parameter>, or the current time if
21
-
<parameter>baseTimestamp</parameter> is not supplied.
21
+
<parameter>baseTimestamp</parameter> is not supplied. The date string parsing
22
+
is defined in <link linkend="datetime.formats">Date and Time Formats</link>, and
23
+
has several subtle considerations. Reviewing the full details there is strongly
24
+
recommended.
22
25
</simpara>
23
26
<warning>
24
27
<para>
...
...
@@ -141,6 +144,18 @@ if (($timestamp = strtotime($str)) === false) {
141
144
&reftitle.notes;
142
145
<note>
143
146
<para>
147
+
"Relative" date in this case also means that if a particular component
148
+
of the date/time stamp is not provided, it will be taken verbatim from
149
+
the <parameter>baseTimestamp</parameter>. That is, <code>strtotime('February')</code>,
150
+
if run on the 31st of May 2022, will be interpreted as <literal>31 February 2022</literal>,
151
+
which will overflow into a timestamp on <literal>3 March</literal>.
152
+
(In a leap year, it would be <literal>2 March</literal>.) Using
153
+
<code>strtotime('1 February')</code> or <code>strtotime('first day of February')</code>
154
+
would avoid that problem.
155
+
</para>
156
+
</note>
157
+
<note>
158
+
<para>
144
159
If the number of the year is specified in a two digit format, the values
145
160
between 00-69 are mapped to 2000-2069 and 70-99 to 1970-1999. See the notes
146
161
below for possible differences on 32bit systems (possible dates might end on
...
...
@@ -162,24 +177,6 @@ if (($timestamp = strtotime($str)) === false) {
162
177
</note>
163
178
<note>
164
179
<para>
165
-
Dates in the <literal>m/d/y</literal> or <literal>d-m-y</literal> formats
166
-
are disambiguated by looking at the separator between the various
167
-
components: if the separator is a slash (<literal>/</literal>), then the
168
-
American <literal>m/d/y</literal> is assumed; whereas if the separator is a
169
-
dash (<literal>-</literal>) or a dot (<literal>.</literal>), then the
170
-
European <literal>d-m-y</literal> format is assumed.
171
-
If, however, the year is given in a two digit format and the separator is a
172
-
dash (<literal>-</literal>), the date string is parsed as
173
-
<literal>y-m-d</literal>.
174
-
</para>
175
-
<para>
176
-
To avoid potential ambiguity, it's best to use ISO 8601
177
-
(<literal>YYYY-MM-DD</literal>) dates or
178
-
<methodname>DateTime::createFromFormat</methodname> when possible.
179
-
</para>
180
-
</note>
181
-
<note>
182
-
<para>
183
180
Using this function for mathematical operations is not advisable.
184
181
It is better to use <methodname>DateTime::add</methodname> and
185
182
<methodname>DateTime::sub</methodname>.
...
...
@@ -191,8 +188,9 @@ if (($timestamp = strtotime($str)) === false) {
191
188
&reftitle.seealso;
192
189
<para>
193
190
<simplelist>
191
+
<member><classname>DateTimeImmutable</classname></member>
192
+
<member><methodname>DateTimeImmutable::createFromFormat</methodname></member>
194
193
<member><link linkend="datetime.formats">Date and Time Formats</link></member>
195
-
<member><methodname>DateTime::createFromFormat</methodname></member>
196
194
<member><function>checkdate</function></member>
197
195
<member><function>strptime</function></member>
198
196
</simplelist>
199
197