By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,711 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,711 IT Pros & Developers. It's quick & easy.

Dates

P: n/a
Hi Guys,

I am in troubles with some dates.
"I need to know the difference, in days, between two
dates."

Well, if the difference is less than a month, so I
could use:

SELECT date_part('day', age(now(), mydate));

But, when it is bigger than a month, the select above
return a wrong information to me:

For instance:

intranet=# select age('30/01/2004', '01/03/2004');
age
-----------------------
@ 1 mon 2 days 1 hour

So, if I use date_part(), it would return "2 days",
not "31 days", that is what I was waiting for.

How can I get the difference, in days, between two
dates???

Thanks in advance and
Best Regards,

__________________________________________________ ____________________

Yahoo! Mail - O melhor e-mail do Brasil! Abra sua conta agora:
http://br.yahoo.com/info/mail.html

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a

Subtracting two dates/timestamps will return an interval. So

select now()::date - '2004-01-13'::date

returns 34.

Is this what you need?

On Feb 16, 2004, at 2:01 PM, MaRCeLO PeReiRA wrote:
Hi Guys,

I am in troubles with some dates.
"I need to know the difference, in days, between two
dates."

Well, if the difference is less than a month, so I
could use:

SELECT date_part('day', age(now(), mydate));

But, when it is bigger than a month, the select above
return a wrong information to me:

For instance:

intranet=# select age('30/01/2004', '01/03/2004');
age
-----------------------
@ 1 mon 2 days 1 hour

So, if I use date_part(), it would return "2 days",
not "31 days", that is what I was waiting for.

How can I get the difference, in days, between two
dates???

Thanks in advance and
Best Regards,

__________________________________________________ ____________________

Yahoo! Mail - O melhor e-mail do Brasil! Abra sua conta agora:
http://br.yahoo.com/info/mail.html

---------------------------(end of
broadcast)---------------------------
TIP 8: explain analyze is your friend

--------------------

Andrew Rawnsley
President
The Ravensfield Digital Resource Group, Ltd.
(740) 587-0114
www.ravensfield.com
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 22 '05 #2

P: n/a

On Mon, 16 Feb 2004, [iso-8859-1] MaRCeLO PeReiRA wrote:
"I need to know the difference, in days, between two
dates."
I think date difference will work, so maybe something like:
CURRENT_DATE - mydate
which should return an integer.
SELECT date_part('day', age(now(), mydate));

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 22 '05 #3

P: n/a
Hi Andrew, and other ones,

It was exactly what I was looking for!!

Thanks!!

Regards,

Marcelo

Ps.: This is the fastest and more efficient mailing
list in the world. Congratulations to all.

--- Andrew Rawnsley <ro**@ravensfield.com> escreveu:

Subtracting two dates/timestamps will return an
interval. So

select now()::date - '2004-01-13'::date

returns 34.

Is this what you need?

On Feb 16, 2004, at 2:01 PM, MaRCeLO PeReiRA wrote:
Hi Guys,

I am in troubles with some dates.
"I need to know the difference, in days, between

two
dates."

Well, if the difference is less than a month, so I
could use:

SELECT date_part('day', age(now(), mydate));

But, when it is bigger than a month, the select

above
return a wrong information to me:

For instance:

intranet=# select age('30/01/2004', '01/03/2004');
age
-----------------------
@ 1 mon 2 days 1 hour

So, if I use date_part(), it would return "2

days",
not "31 days", that is what I was waiting for.

How can I get the difference, in days, between two
dates???

Thanks in advance and
Best Regards,

__________________________________________________ ____________________

Yahoo! Mail - O melhor e-mail do Brasil! Abra sua

conta agora:
http://br.yahoo.com/info/mail.html

---------------------------(end of
broadcast)---------------------------
TIP 8: explain analyze is your friend

--------------------

Andrew Rawnsley
President
The Ravensfield Digital Resource Group, Ltd.
(740) 587-0114
www.ravensfield.com


__________________________________________________ ____________________

Yahoo! Mail - O melhor e-mail do Brasil! Abra sua conta agora:
http://br.yahoo.com/info/mail.html

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.