Re: How can I replace the year of the created_at column with the current year dynamically ?

From: Michael Paquier <michael(dot)paquier(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 replace the year of the created_at column with the current year dynamically ?
Date: 2014-07-02 07:26:05
Message-ID: CAB7nPqSkadfdvATvs9rE-8WJY6_pA+rAcS-GdRktWJEpScs0uQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Jul 2, 2014 at 3:27 PM, Arup Rakshit <aruprakshit(at)rocketmail(dot)com>
wrote:

> Here is my try :
>
> staging::=> select to_char(created_at,'DD/MM') || '/' ||
> to_char(now(),'YYYY') as when from users;
> when
> ------------
> 24/02/2014
> 28/02/2014
> 02/03/2014
> 01/03/2014
> 04/03/2014
> 02/03/2014
> 06/03/2014
> 07/05/2014
> 02/06/2014
> 06/06/2014
> 20/02/2014
> 20/02/2014
> 20/02/2014
> 20/06/2014
> 20/02/2014
> (15 rows)
>
> Can the same be done using any other clever trick ?
>
What is the data at your disposal when trying to select the current year?
If it is a timestamp, simply use date_part:
=# select date_part('year', now());
date_part
-----------
2014
(1 row)
--
Michael

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Arup Rakshit 2014-07-02 07:48:08 Re: How can I replace the year of the created_at column with the current year dynamically ?
Previous Message Jacob Bunk Nielsen 2014-07-02 06:33:49 Re: Two-way encryption