Re: Make year 01/01/0001 but leave timestamp alone - Mailing list pgsql-novice

From Tom Lane
Subject Re: Make year 01/01/0001 but leave timestamp alone
Date
Msg-id 24440.1123016229@sss.pgh.pa.us
Whole thread Raw
In response to Re: Make year 01/01/0001 but leave timestamp alone  (John DeSoi <desoi@pgedit.com>)
List pgsql-novice
John DeSoi <desoi@pgedit.com> writes:
> On Aug 2, 2005, at 11:49 AM, Walker, Jed S wrote:
>> I have a situation where we have a timestamp column but in special
>> cases we want to set the date to '01/01/0001' and leave the
>> timestamp alone. For example, '11/04/2005 10:30:05' would become
>> '01/01/0001 10:30:05'. I've been going through the various date
>> time functions but don't see a simple way to do this. Can someone
>> help?

> select ('0001-01-01 ' || now()::time::text)::timestamp;

This textual pasting makes me itch ... try something like

select '0001-01-01'::timestamp + now()::time;
          ?column?
----------------------------
 0001-01-01 16:56:16.313866
(1 row)


            regards, tom lane

pgsql-novice by date:

Previous
From: "Keith Worthington"
Date:
Subject: Re: boolean or int2
Next
From: "Walker, Jed S"
Date:
Subject: Re: Make year 01/01/0001 but leave timestamp alone