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

From: John DeSoi <desoi(at)pgedit(dot)com>
To: "Walker, Jed S" <Jed_Walker(at)cable(dot)comcast(dot)com>
Cc: <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Make year 01/01/0001 but leave timestamp alone
Date: 2005-08-02 16:35:56
Message-ID: C4C31703-544A-45D1-999A-46C7A4BF4B9D@pgedit.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice pgsql-sql


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;

timestamp
----------------------------
0001-01-01 12:31:52.815674
(1 row)

Just replace now() with whatever timestamp you are using.

John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Walker, Jed S 2005-08-02 17:05:15 Re: Make year 01/01/0001 but leave timestamp alone
Previous Message daq 2005-08-02 16:22:27 Re: [NOVICE] Make year 01/01/0001 but leave timestamp alone

Browse pgsql-sql by date

  From Date Subject
Next Message Henry Ortega 2005-08-02 18:34:46 Breakdown results by month
Previous Message daq 2005-08-02 16:22:27 Re: [NOVICE] Make year 01/01/0001 but leave timestamp alone