From: | Huan Ruan <huan(dot)ruan(dot)it(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | DateDiff() function |
Date: | 2013-07-11 05:17:53 |
Message-ID: | CAD1stZuwG5fx4YJ+dyFRuxEaCmYo+nUWJvwuP-=FUTEA463PdQ@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Hi Guys
We are migrating to Postgres. In the current system, we use datediff()
function to get the difference between two dates, e.g. datediff (month,
cast('2013-01-01' as timestamp), cast('2013-02-02' as timestamp) returns 1.
I understand that Postgres has Interval data type so I can achieve the same
with Extract(month from Age(date1, date2)). However, I try to make it so
that the existing SQL can run on both databases without changes. One
possible way is to add a datediff function to Postgres, but the problem is
that month/day/year etc is a keyword not a string like 'month'. I noticed
that Postgres seems to convert Extract(month from current_timestamp) to
date_part('month', current_timestamp), you can also do Extract('month' from
current_timestamp). So it seems internally, Postgres can do the mapping
from month to 'month'. I was wondering if there is a way for me to do the
same for the datediff() function? Any other ideas?
Thanks
Huan
From | Date | Subject | |
---|---|---|---|
Next Message | Gavin Flower | 2013-07-11 06:18:57 | Re: DateDiff() function |
Previous Message | Igor Neyman | 2013-07-09 20:36:56 | Re: delete where not in another table |