php-doc-en/reference/datetime/dateinterval/construct.xml

150 lines
3.9 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="dateinterval.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>DateInterval::__construct</refname>
<refpurpose>Creates new DateInterval object</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<methodname>DateInterval::__construct</methodname>
<methodparam><type>string</type><parameter>interval_spec</parameter></methodparam>
</methodsynopsis>
<para>
Creates new DateInterval object.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>interval_spec</parameter></term>
<listitem>
<para>
Interval specification.
</para>
<para>
The <emphasis>date portion</emphasis>, if any,
starts with the letter <literal>P</literal>.
Each date unit is represented by an integer value
followed by the letter indicating the unit type.
The date unit types are
<literal>Y</literal> for years,
<literal>M</literal> for months and
<literal>D</literal> for days.
For example, the format to create a two day
interval is <literal>P2D</literal>.
</para>
<para>
The <emphasis>time portion</emphasis>, if any,
starts with the letter <literal>T</literal>.
Each time unit is represented by an integer value
followed by the letter indicating the unit type.
The time unit types are
<literal>H</literal> for hours,
<literal>M</literal> for minutes and
<literal>S</literal> for seconds.
For example, the format to create a two second
interval is <literal>T2S</literal>.
</para>
<para>
The date and time portions can be combined. To
demonstrate, an interval of six years and five minutes
is represented by <literal>P6YT5M</literal>.
</para>
<note>
<para>
The unit types must be entered from the largest
scale unit on the left to the smallest scale unit
on the right.
So years before months, months before days,
days before minutes, etc.
Thus one year and four days must be represented as
<literal>P1Y4D</literal>, not <literal>P4D1Y</literal>.
</para>
</note>
<para>
The format can also be entered in an ISO format.
A sample of one year and four days would be
<literal>P0001-00-04T00:00:00</literal>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<programlisting role="php">
<![CDATA[
<?php
$interval = new DateInterval('P2Y4DT6H8M');
print_r($interval);
?>
]]>
</programlisting>
&example.outputs;
<screen role="php">
<![CDATA[
DateInterval Object
(
[y] => 2
[m] => 0
[d] => 4
[h] => 6
[i] => 8
[s] => 0
[invert] => 0
[days] => 0
)
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>DateInterval::format</function></member>
<member><function>DateTime::add</function></member>
<member><function>DateTime::sub</function></member>
<member><function>DateTime::diff</function></member>
</simplelist>
</para>
</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:"../../../../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
-->