Re: Calculating Differences Between Dates - Problem

Поиск
Список
Период
Сортировка
От Jean-Luc Lachance
Тема Re: Calculating Differences Between Dates - Problem
Дата
Msg-id 3E1F3FC1.1F400709@nsd.ca
обсуждение исходный текст
Ответ на Calculating Differences Between Dates - Problem  (Hunter Hillegas <lists@lastonepicked.com>)
Список pgsql-general
Try:

Select int4( extract( epoch from
age(timestamptz(sample_request_line_item.date_shipped),
sample_request.date_of_request))/86400);



Hunter Hillegas wrote:
>
> I am trying to calculate the number of days between two dates.
>
> Right now I have this query fragment:
>
>  date_part('day'::text,
> age(timestamptz(sample_request_line_item.date_shipped),
>  AS date_difference
>
> This works as long as the date doesn't span the month. In those cases I get
> bad values. i.e.:
>
> date_shipped: 2003-01-10
> date_of_request: 2003-01-09
> date_difference: -1
> OK
>
> date_shipped: 2003-01-10
> date_of_request: 2003-01-09
> date_difference: -1
> OK
>
> date_shipped: 2002-12-16
> date_of_request: 2002-10-29
> date_difference: 18
> NOT OK - it is more days than this.
>
> Looks like I am just not printing out the month as well as the day
> difference... But I need it all translated into days, not month(s)+days(s).
> Can I do this?
>
> Thanks,
> Hunter
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster

В списке pgsql-general по дате отправления:

Предыдущее
От: Steve Crawford
Дата:
Сообщение: SCO 5.0.4 Compilation
Следующее
От: pippo@bellnet.ca
Дата:
Сообщение: cannot modify user