Re: Make year 01/01/0001 but leave timestamp alone

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: John DeSoi <desoi(at)pgedit(dot)com>
Cc: "Walker, Jed S" <Jed_Walker(at)cable(dot)comcast(dot)com>, pgsql-novice(at)postgresql(dot)org
Subject: Re: Make year 01/01/0001 but leave timestamp alone
Date: 2005-08-02 20:57:09
Message-ID: 24440.1123016229@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql

John DeSoi <desoi(at)pgedit(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Walker, Jed S 2005-08-02 21:44:30 Re: Make year 01/01/0001 but leave timestamp alone
Previous Message Keith Worthington 2005-08-02 18:52:16 Re: boolean or int2

Browse pgsql-sql by date

  From Date Subject
Next Message Chris Travers 2005-08-03 00:54:59 Re: Trigger on select?
Previous Message Henry Ortega 2005-08-02 18:34:46 Breakdown results by month