Re: Reg Date/Time function

From: Sandeep Segu <segu(dot)sandeep(at)gmail(dot)com>
To: Mike Toews <mwtoews(at)gmail(dot)com>
Cc: pgsql-docs(at)postgresql(dot)org
Subject: Re: Reg Date/Time function
Date: 2017-08-02 00:32:04
Message-ID: CAHkhDrs2jjWh5PjfRqypZhvFZB5BDpz8ahJXfZZbUrJD8LYK3Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

Thank you Mike.. Great information.
I heard about the 360-day calendar, for the first time and I am so thankful
to you for this. I appreciate your time.

Thanks,
Sandeep Segu.

On Tue, Aug 1, 2017 at 7:20 PM, Mike Toews <mwtoews(at)gmail(dot)com> wrote:

> On 1 August 2017 at 12:30, <segu(dot)sandeep(at)gmail(dot)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
> &quot;justify_days(interval)&quot;
> >
> > select justify_days(interval &#39;365 days&#39;);
> >
> > 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
>

In response to

Browse pgsql-docs by date

  From Date Subject
Next Message Jürgen Purtz 2017-08-02 07:28:20 Re: Use of term Master/Slave
Previous Message Mike Toews 2017-08-01 23:26:35 Re: Use of term Master/Slave