Re: How Many Years have Passed?
От | Ian Harding |
---|---|
Тема | Re: How Many Years have Passed? |
Дата | |
Msg-id | sc22ff16.026@mail.tpchd.org обсуждение исходный текст |
Ответ на | How Many Years have Passed? ("Ian Harding" <ianh@tpchd.org>) |
Список | 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@tpchd.org >>> lockhart@fourpalms.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@postgresql.org)
В списке pgsql-general по дате отправления: