Re: Determining period between 2 dates
| От | Marti Raudsepp |
|---|---|
| Тема | Re: Determining period between 2 dates |
| Дата | |
| Msg-id | AANLkTi=c4VB38DkyiC4VQfA9Ak+Gyy+EJNOe1eHjOFg-@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: Determining period between 2 dates (Thom Brown <thom@linux.com>) |
| Ответы |
Re: Determining period between 2 dates
|
| Список | pgsql-hackers |
On Wed, Feb 16, 2011 at 18:03, Thom Brown <thom@linux.com> wrote: > For the number of fortnights, that becomes: > > select extract(epoch from now() - '2010-01-01 11:45:13'::timestamp)/60/60/24/14; > > You'd think with PostgreSQL having such a rich type system, it > wouldn't need to come to that. It's just asking for the number of > intervals between 2 timestamps rather than the number of seconds and > dividing it to the point you get your answer. I think a good generic solution would be an interval/interval operator that returns numeric. Then the above becomes: SELECT (now() - timestamp '2010-01-01 11:45:13') / interval '2 weeks'; However, looking at the code, it's not so obvious what to do if the intervals contain months. Regards, Marti
В списке pgsql-hackers по дате отправления: