Re: date with month and year

From: "Joshua D(dot) Drake" <jd(at)commandprompt(dot)com>
To: Daniel Torres <nobeeakon(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: date with month and year
Date: 2015-05-21 17:31:14
Message-ID: 555E1662.2070807@commandprompt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/21/2015 10:01 AM, Daniel Torres 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);

date_part will get you what you want as will to_char. The above you
could cast if you needed. You really shouldn't use WITHOUT TIME ZONE.

JD

--
The most kicking donkey PostgreSQL Infrastructure company in existence.
The oldest, the most experienced, the consulting company to the stars.
Command Prompt, Inc. http://www.commandprompt.com/ +1 -503-667-4564 -
24x7 - 365 - Proactive and Managed Professional Services!

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2015-05-21 17:44:27 Re: date with month and year
Previous Message Paul Jungwirth 2015-05-21 17:13:19 Re: date with month and year