Re: Time and date functions give me headaches!!

From: Scott Marlowe <smarlowe(at)g2switchworks(dot)com>
To: Costin Manda <siderite(at)madnet(dot)ro>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Time and date functions give me headaches!!
Date: 2005-04-11 15:24:17
Message-ID: 1113233057.20921.96.camel@state.g2switchworks.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 2005-04-11 at 04:40, Costin Manda wrote:
> Hello,
>
> I have a table with columns defines as varchar that have values in format
> 'YYYY-MM-DD HH:MM:SS'.
>
> Now, if I do a
> select timestamp '2005-10-10 10:10:10';
> I get the value just fine. I can use abstime()::integer on the result to
> find the unix timestamp. (This is the simplest way I could find, are there
> any others?)
>
> However, when I try doing the same with the values in the table I can't
> get it to work.
>
> select timestamp setuptime from billing; - error
> select timestamp(setuptime) from billing; - error
> select setuptime::timestamp from billing; - error (cannot cast type
> character varying to timestamp without timezone!?)
>
> So, how can I convert this string into a timestamp, pleeease! :(

More importantly, why are you storing your timestamps as strings?
Sotring them as timestamps is the proper way to do things. It provides
bounds checking, and allows date maths to be done rather simply.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message PFC 2005-04-11 15:25:39 Re: pg 8.0.1-r3 killls pgadmin3 and phppgadmin
Previous Message Scott Marlowe 2005-04-11 15:22:11 Re: What are the consequences of a bad database design