| From: | "Ian Harding" <ianh(at)tpchd(dot)org> |
|---|---|
| To: | <lockhart(at)fourpalms(dot)org>, <thomas(at)pgsql(dot)com>, <greg(at)turnstep(dot)com> |
| Cc: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: How Many Years have Passed? |
| Date: | 2001-12-21 17:19:51 |
| Message-ID: | sc22ff16.026@mail.tpchd.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Yikes! Who knew there was an age() function? Thanks!! Although it calls for timestamp arguments, it works with date. Are dates usually implicitly cast to timestamp in functions?
test=# \df age
List of functions
Result | Function | Arguments
----------+----------+----------------------------------------------------
interval | age | timestamp with time zone
interval | age | timestamp with time zone, timestamp with time zone
(2 rows)
Ian A. Harding
Programmer/Analyst II
Tacoma-Pierce County Health Department
(253) 798-3549
mailto: iharding(at)tpchd(dot)org
>>> lockhart(at)fourpalms(dot)org 12/20/01 05:34PM >>>
> > I have checked the FAQ and other sources and learned that the difference
> > between two dates is the integer number of days. I want to know how many
> > years are between those two dates.
thomas=# select age(date 'today', date '1980-01-01'),
thomas-# extract(year from age(date 'today', date '1980-01-01'));
age | date_part
--------------------------+-----------
21 years 11 mons 20 days | 21
Is this close to what you want? The nice thing about the age() function
is that it preserves the qualitative units of month and year.
- Thomas
---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Antonio Fiol Bonnín | 2001-12-21 17:41:41 | Re: Database tuning |
| Previous Message | K Old | 2001-12-21 17:03:43 | Database tuning |