Re: subtract two dates to get the number of days

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Campbell, Lance" <lance(at)illinois(dot)edu>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: subtract two dates to get the number of days
Date: 2010-07-13 15:02:10
Message-ID: 29026.1279033330@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

"Campbell, Lance" <lance(at)illinois(dot)edu> writes:
> I want to subtract to dates to know the number of days different.
> Example:
> 01/02/2010 - 01/01/2010 = 1 day
> 08/01/2010 - 07/31/2010 = 1 day
> How do I do this?

If they're dates, you just subtract.

regression=# select '08/01/2010'::date - '07/31/2010'::date;
?column?
----------
1
(1 row)

regards, tom lane

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas Kellerer 2010-07-13 15:05:12 Re: subtract two dates to get the number of days
Previous Message Campbell, Lance 2010-07-13 14:58:53 subtract two dates to get the number of days