pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: Mark <mark@zserve.com>
To: pgsql-sql@postgresql.org
Subject: Re: Date manipulation
Date: Fri, 01 Jun 2001 09:21:17 -0700
Message-ID: <web-65757@davinci.ethosmedia.com> (raw)
In-Reply-To: <200105311714.f4VHEbW24511@mail.ldssingles.com>

Mark,

> How does one perform date manipulation within SQL?  For example, SQL
> Server has a dateadd() function that takes a date part, scalar, and
> the
> date to manipulate.

As I have remarked before, such functions as DATEADD are unnecessary in
PostgreSQL because PostgreSQL has a proper implementation of Date data
types, unlike MS SQL Server.  Thus, to add to a date:

	new_date := old_date + INTERVAL('1 week');

Or to subtract:

	break_time := restart_time - stop_time;

It's improtant to remeber that the differnence of two dates or times is
an interval, and while you can add an interval to a date you cannot add
two dates.

Additionally, if you browse to Roberto Mello's PG/plSQL function library
(see link for the PostgreSQL.org web site) you will find an extension to
the OVERLAPS function that I find quite useful (I should, I wrote it!).

-Josh


______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco



view thread (7+ messages)  latest in thread

Message-ID: <web-65757@davinci.ethosmedia.com>
Permalink:  ../web-65757@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-65757@davinci.ethosmedia.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, mark@zserve.com
  Subject: Re: Date manipulation
  In-Reply-To: <web-65757@davinci.ethosmedia.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox