From: | Arup Rakshit <aruprakshit(at)rocketmail(dot)com> |
---|---|
To: | "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:48:08 |
Message-ID: | 1404287288.23919.YahooMailNeo@web193906.mail.sg3.yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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
It is *datetime*. Now my users are created at different date...
say -
user1 24/02/1997
user2 28/02/2011
user3 02/03/2001
user4 01/03/2003
.....
But I have some requirment, where date/month part will be as it is... but as per the current year, I will replace the actual year with the current year, while I will be displaying it. To meet this need, I am currently doing as
select to_char(created_at,'DD/MM') || '/' || to_char(now(),'YYYY') as when from users;
From | Date | Subject | |
---|---|---|---|
Next Message | Stuart Bishop | 2014-07-02 08:46:51 | Re: Very high latency, low bandwidth replication |
Previous Message | Michael Paquier | 2014-07-02 07:26:05 | Re: How can I replace the year of the created_at column with the current year dynamically ? |