Re: How can I get first day date of the previous month ?

From: Alban Hertroys <haramrae(at)gmail(dot)com>
To: Arup Rakshit <aruprakshit(at)rocketmail(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How can I get first day date of the previous month ?
Date: 2014-06-20 08:52:49
Message-ID: CAF-3MvPGpzhc9=MWos+VU9xqJHd6kKuuGZprUyDEDHNus6Ao7A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 20 June 2014 09:11, Arup Rakshit <aruprakshit(at)rocketmail(dot)com> wrote:
> Thanks for your answer. How to get the first day date of last 6 months from
> now then will be :
>
> yelloday_development=# select date_trunc('month', now()) - interval '5
> month' as first_month;
> first_month
> ---------------------------
> 2014-01-01 00:00:00+05:30
> (1 row)
>
> Is it correct ? I am new pgdql DB :-) Awesome DB it is...

It is.

You can also do it like this to get the first day of each of the last 6 months:

=# select date_trunc('month', now()) - interval '1 month' * n from
generate_series(1, 6) as i(n);
?column?
------------------------
2014-05-01 00:00:00+02
2014-04-01 00:00:00+02
2014-03-01 00:00:00+01
2014-02-01 00:00:00+01
2014-01-01 00:00:00+01
2013-12-01 00:00:00+01
(6 rows)

--
If you can't see the forest for the trees,
Cut the trees and you'll see there is no forest.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Khangelani Gama 2014-06-20 11:01:22 Re: pg_restore: custom archiver unexpected end of file , ERROR: missing data for column
Previous Message Dick Kniep 2014-06-20 08:18:43 Strange Error in postgresql 8.4