From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | Daniel Torres <nobeeakon(at)gmail(dot)com> |
Cc: | "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: date with month and year |
Date: | 2015-05-21 17:13:15 |
Message-ID: | CAKFQuwZhS-f3HZyzJpHLb80LvZdD=-4uNN5om5Z0XF1rd4BMNA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thursday, May 21, 2015, Daniel Torres <nobeeakon(at)gmail(dot)com> wrote:
> I everybody, I'm new in the Postgresql world, and have an easy question:
> Is it possible to have date type data that only contain month and year?,
> how can I obtain that from a timestamp (without time zone) column?
>
> I've made this, but I think the result is a text, not a date
>
> select extract (Year from '2001-05-01 20:21:00'::TIMESTAMP WITHOUT TIME
> ZONE)||'-'|| extract(Month from '2001-05-01 20:21:00'::TIMESTAMP WITHOUT
> TIME ZONE);
>
>
You have to settle for the first of the month if you want a date type.
Date_trunc(day,...) will give you that.
I do end up having a lookup tha gassing sequential integers to sequential
year-months to make calculations easier without having to carry around a
date type for that sole purpose. For presentation I want text, not a date.
User defined functions are nice here - I have a todo to publish my set to
PGXN...maybe someone else already has?
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | Paul Jungwirth | 2015-05-21 17:13:19 | Re: date with month and year |
Previous Message | John McKown | 2015-05-21 17:11:43 | Re: date with month and year |