timestamp from another one and save the result in a
variable of type interval.
<synopsis>
int PGTYPEStimestamp_sub(timestamp *ts1, timestamp *ts2, interval *iv);
</synopsis>
The function will subtract the timestamp variable that <literal>ts2</literal>
points to from the timestamp variable that <literal>ts1</literal> points to
and will store the result in the interval variable that <literal>iv</literal>
points to.
</para>
<para>
Upon success, the function returns 0 and a negative value if an
error occurred.
</para>
</listitem>
</varlistentry>
<varlistentry id="pgtypestimestampdefmtasc">
<term><function>PGTYPEStimestamp_defmt_asc</function></term>
<listitem>
<para>
Parse a timestamp value from its textual representation using a
formatting mask.
<synopsis>
int PGTYPEStimestamp_defmt_asc(char *str, char *fmt, timestamp *d);
</synopsis>
The function receives the textual representation of a timestamp in the
variable <literal>str</literal> as well as the formatting mask to use in the
variable <literal>fmt</literal>. The result will be stored in the variable
that <literal>d</literal> points to.
</para>
<para>
If the formatting mask <literal>fmt</literal> is NULL, the function will fall
back to the default formatting mask which is <literal>%Y-%m-%d
%H:%M:%S</literal>.
</para>
<para>
This is the reverse function to <xref
linkend="pgtypestimestampfmtasc"/>. See the documentation there in
order to find out about the possible formatting mask entries.
</para>
</listitem>
</varlistentry>
<varlistentry id="pgtypestimestampaddinterval">
<term><function>PGTYPEStimestamp_add_interval</function></term>
<listitem>
<para>
Add an interval variable to a timestamp variable.
<synopsis>
int PGTYPEStimestamp_add_interval(timestamp *tin, interval *span, timestamp *tout);
</synopsis>
The function receives a pointer to a timestamp variable <literal>tin</literal>
and a pointer to an interval variable <literal>span</literal>. It adds the
interval to the timestamp and saves the resulting timestamp in the
variable that <literal>tout</literal> points to.
</para>
<para>
Upon success, the function returns 0 and a negative value if an
error occurred.
</para>
</listitem>
</varlistentry>
<varlistentry id="pgtypestimestampsubinterval">
<term><function>PGTYPEStimestamp_sub_interval</function></term>
<listitem>
<para>
Subtract an interval variable from a timestamp variable.
<synopsis>
int PGTYPEStimestamp_sub_interval(timestamp *tin, interval *span, timestamp *tout);
</synopsis>
The function subtracts the interval variable that <literal>span</literal>
points to from the timestamp variable that <literal>tin</literal> points to
and saves the result into the variable that <literal>tout</literal> points
to.
</para>
<para>
Upon success, the function returns 0 and a negative value if an
error occurred.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</sect2>
<sect2 id="ecpg-pgtypes-interval">
<title>The interval Type</title>
<para>
The interval type in C enables your programs to deal with data of the SQL
type interval. See <xref linkend="datatype-datetime"/> for the equivalent
type in the <productname>PostgreSQL</productname> server.
</para>
<para>
The following functions can be used to work with the interval type:
<variablelist>
<varlistentry id="pgtypesintervalnew">
<term><function>PGTYPESinterval_new</function></term>
<listitem>
<para>
Return a pointer to a newly allocated interval variable.
<synopsis>
interval *PGTYPESinterval_new(void);