pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedDateDiff in PostgreSQL
6+ messages / 5 participants
[nested] [flat]
* DateDiff in PostgreSQL
@ 2003-11-07 13:34 George A.J <jinujosein@yahoo.com>
2003-11-07 13:40 ` Re: DateDiff in PostgreSQL Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>
2003-11-07 13:47 ` Re: DateDiff in PostgreSQL Tomasz Myrta <jasiek@klaster.net>
2003-11-07 13:55 ` Re: DateDiff in PostgreSQL Rod Taylor <pg@rbt.ca>
0 siblings, 3 replies; 6+ messages in thread
From: George A.J @ 2003-11-07 13:34 UTC (permalink / raw)
To: pgsql-sql
Hi,
i am converting a MSSQL Server database to PostgreSQL.
Using PostgreSQL version 7.3.2.
Is there any function like the DateDiff() in MSSQL Server.
ie, a function that returns difference of two dates(timestamp) in days or months or year..
The - operator for timestamp retuns the intervel in days only.
Please help
jinujose
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DateDiff in PostgreSQL
2003-11-07 13:34 DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
@ 2003-11-07 13:40 ` Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>
2003-11-07 13:53 ` Re: DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
2 siblings, 1 reply; 6+ messages in thread
From: Yasir Malik @ 2003-11-07 13:40 UTC (permalink / raw)
To: George A.J <jinujosein@yahoo.com>; +Cc: pgsql-sql
Hi,
You can use the age() function to find the difference between dates, and
use the extract() function to get the years, months, days, etc.
Yasir
On Fri, 7 Nov 2003, George A.J wrote:
> Date: Fri, 7 Nov 2003 05:34:09 -0800 (PST)
> From: George A.J <jinujosein@yahoo.com>
> To: pgsql-sql@postgresql.org
> Subject: [SQL] DateDiff in PostgreSQL
>
>
> Hi,
>
> i am converting a MSSQL Server database to PostgreSQL.
>
> Using PostgreSQL version 7.3.2.
>
> Is there any function like the DateDiff() in MSSQL Server.
>
> ie, a function that returns difference of two dates(timestamp) in days or months or year..
>
> The - operator for timestamp retuns the intervel in days only.
>
> Please help
>
> jinujose
>
>
> ---------------------------------
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DateDiff in PostgreSQL
2003-11-07 13:34 DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
2003-11-07 13:40 ` Re: DateDiff in PostgreSQL Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>
@ 2003-11-07 13:53 ` George A.J <jinujosein@yahoo.com>
0 siblings, 0 replies; 6+ messages in thread
From: George A.J @ 2003-11-07 13:53 UTC (permalink / raw)
To: Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>; +Cc: pgsql-sql
Yasir Malik <ymalik@heineken.cs.stevens-tech.edu> wrote:
>You can use the age() function to find the difference between dates, and
>use the extract() function to get the years, months, days, etc.
>Yasir
this will not work because age('25/12/1975','30/01/1986')
wil return '10 year 1 month 5 days'
extract only returns years -10, moths-1, days-5.
this is not i want.Actual month difference between the dates are 121 months.
jinu jose
---------------------------------
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DateDiff in PostgreSQL
2003-11-07 13:34 DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
@ 2003-11-07 13:47 ` Tomasz Myrta <jasiek@klaster.net>
2 siblings, 0 replies; 6+ messages in thread
From: Tomasz Myrta @ 2003-11-07 13:47 UTC (permalink / raw)
To: George A.J <jinujosein@yahoo.com>; +Cc: pgsql-sql
Dnia 2003-11-07 14:34, Użytkownik George A.J napisał:
> Hi,
>
> i am converting a MSSQL Server database to PostgreSQL.
>
> Using PostgreSQL version 7.3.2.
>
> Is there any function like the DateDiff() in MSSQL Server.
>
> ie, a function that returns difference of two dates(timestamp) in days
> or months or year..
>
> The - operator for timestamp retuns the intervel in days only.
1. You can convert timestamps to dates and then substract them. The
result will be days::integer.
2. Interval result is not a problem - you can extract epoch from it. The
result is seconds::integer - do whatever you want with it.
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DateDiff in PostgreSQL
2003-11-07 13:34 DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
@ 2003-11-07 13:55 ` Rod Taylor <pg@rbt.ca>
2 siblings, 0 replies; 6+ messages in thread
From: Rod Taylor @ 2003-11-07 13:55 UTC (permalink / raw)
To: George A.J <jinujosein@yahoo.com>; +Cc: pgsql-sql
> ie, a function that returns difference of two dates(timestamp) in days
> or months or year..
>
> The - operator for timestamp retuns the intervel in days only.
rbt=# select extract('days' from current_timestamp -
'2003-01-01'::timestamp);
date_part
-----------
310
(1 row)
^ permalink raw reply [nested|flat] 6+ messages in thread
* Re: DateDiff in PostgreSQL
@ 2003-11-07 13:45 Yasir Malik <ymalik@cs.stevens-tech.edu>
0 siblings, 0 replies; 6+ messages in thread
From: Yasir Malik @ 2003-11-07 13:45 UTC (permalink / raw)
To: jinujosein@yahoo.com; +Cc: pgsql-sql
Hi,
You can use the age() function to find the difference between dates, and
use the extract() function to get the years, months, days, etc.
Yasir
On Fri, 7 Nov 2003, George A.J wrote:
> Date: Fri, 7 Nov 2003 05:34:09 -0800 (PST)
> From: George A.J <jinujosein@yahoo.com>
> To: pgsql-sql@postgresql.org
> Subject: [SQL] DateDiff in PostgreSQL
>
>
> Hi,
>
> i am converting a MSSQL Server database to PostgreSQL.
>
> Using PostgreSQL version 7.3.2.
>
> Is there any function like the DateDiff() in MSSQL Server.
>
> ie, a function that returns difference of two dates(timestamp) in days or months or year..
>
> The - operator for timestamp retuns the intervel in days only.
>
> Please help
>
> jinujose
>
>
> ---------------------------------
> Do you Yahoo!?
> Protect your identity with Yahoo! Mail AddressGuard
^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2003-11-07 13:55 UTC | newest]
Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-11-07 13:34 DateDiff in PostgreSQL George A.J <jinujosein@yahoo.com>
2003-11-07 13:40 ` Yasir Malik <ymalik@heineken.cs.stevens-tech.edu>
2003-11-07 13:53 ` George A.J <jinujosein@yahoo.com>
2003-11-07 13:47 ` Tomasz Myrta <jasiek@klaster.net>
2003-11-07 13:55 ` Rod Taylor <pg@rbt.ca>
2003-11-07 13:45 Re: DateDiff in PostgreSQL Yasir Malik <ymalik@cs.stevens-tech.edu>
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