Re: [DOCS] Reg Date/Time function

Поиск
Список
Период
Сортировка
От Mike Toews
Тема Re: [DOCS] Reg Date/Time function
Дата
Msg-id CAM2FmMr5wfUBnNZk=v1XFYfLzW__eEW5S9giWVrJWQCaZECSCA@mail.gmail.com
обсуждение исходный текст
Ответ на [DOCS] Reg Date/Time function  (segu.sandeep@gmail.com)
Ответы Re: [DOCS] Reg Date/Time function  (Sandeep Segu <segu.sandeep@gmail.com>)
Список pgsql-docs
On 1 August 2017 at 12:30,  <segu.sandeep@gmail.com> wrote:
> Hi,
> I am going through PostgreSQL, for the first day. And it was great till
> now.
> One quick question/doubt regarding the function "justify_days(interval)"
>
> select justify_days(interval '365 days');
>
> this statement returns  1 year 5 days, whereas I feel it should be just 1
> year.
>
> Please correct me if I am wrong.. Thanks for all your time.

It seems you are trying to convert a time interval type to days. The
most reliable way to get this is to extract the epoch, which is in
number of seconds, then convert this to days (divide by 60 * 60 * 24).

SELECT x, extract(epoch from x)/86400 AS days
FROM (
  SELECT '1 year'::interval AS x
  UNION ALL SELECT '365 days'
) AS sub;

    x     |  days
----------+--------
 1 year   | 365.25
 365 days |    365
(2 rows)

A typical "year" indeed has 365.25 days, when you consider leap years
typically every 4th. As noted previously, justify_days(interval) has a
special use for 360-day calendars[1].

[1] https://en.wikipedia.org/wiki/360-day_calendar


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

Предыдущее
От: Jonathan Katz
Дата:
Сообщение: Re: [DOCS] Use of term Master/Slave
Следующее
От: Mike Toews
Дата:
Сообщение: Re: [DOCS] Use of term Master/Slave