Re: mapping date value (SQL question) - Mailing list pgsql-general

From Thomas Lockhart
Subject Re: mapping date value (SQL question)
Date
Msg-id 3C750FD1.4D5DB582@fourpalms.org
Whole thread Raw
In response to mapping date value (SQL question)  ("Johnson, Shaunn" <SJohnson6@bcbsm.com>)
List pgsql-general
> "Johnson, Shaunn" wrote:
> I've created a table which includes the date.  I have been instructed
> to map the date into something that reflects the quarter of the year
> on the fly (somewhere in the script).  For example:
> (currently) date:               (needed) quarter:
> 2001-02-26                      200101
> 1998-05-12                      199802
> 803-11-11                       80304
> Is there such a mechanism to do what is being asked of me?

select date_part('quarter', date 'now');

gets you the current quarter, and

select date_part('year', date 'now') || date_part('quarter', date
'now');

gets you both year and quarter.

However, you may want to use the to_char() functionality to get more
control over the formatting:

select to_char(date 'now', 'YYYY0Q');

Good luck!

                   - Thomas

pgsql-general by date:

Previous
From: Jeff Self
Date:
Subject: Re: mapping date value (SQL question)
Next
From: "paul simdars"
Date:
Subject: ANY GOOD USER'S GUIDE ONLINE?? (with simple examples)