Thread: Time Conversion

Time Conversion

From
"Ryan Sommers"
Date:
How can I convert a VARCHAR(25) to a timestamp? Including a fraction of a
second.

The VARCHAR(25) column is in the form: YYYY-MM-DD HH:MI:SS.fffff
where fffff is the fraction of a second.

I could use to_timestamp but I can't find a conversion specifier for the
fractional part.


--
Ryan Sommers
ryans@gamersimpact.com


Re: Time Conversion

From
Tom Lane
Date:
"Ryan Sommers" <ryans@gamersimpact.com> writes:
> How can I convert a VARCHAR(25) to a timestamp? Including a fraction of a
> second.

> The VARCHAR(25) column is in the form: YYYY-MM-DD HH:MI:SS.fffff
> where fffff is the fraction of a second.

> I could use to_timestamp but I can't find a conversion specifier for the
> fractional part.

Since that's a perfectly valid input format for timestamp, you could
just cast it.

regression=# select '2005-05-27 11:22:33.4567'::varchar::timestamp;
        timestamp
--------------------------
 2005-05-27 11:22:33.4567
(1 row)

            regards, tom lane