By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

How to cast varchar into timestamp in postgres

P: 4
I have a table (which i cannot modify) where date and time fields are stored as VARCHAR. But i have to cast these fields into timestamp.

My requirement is like,
timestamp (select date, time where max(timestamp(date,time));

How to do this in postgres?
Dec 29 '06 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 534
I'm not sure if you can really cast varchar into timestamp, (although I don't have the latest version of Postgres, which may have a larger set of cast operators), but you can try something like this instead:

Expand|Select|Wrap|Line Numbers
  1. select (mydate || ' ' || mytime) from foo where (mydate || ' ' || mytime) = (select max (mydate || ' ' || mytime) from foo);
Dec 29 '06 #2

P: 4
Thank you,
I found a function to_timestamp and it casts string into timestamp
I tried sth like ,

to_timestamp('01 Jan 2007 09:09:09', 'DD Mon YYYY HH:MI:SS')

It works .
Jan 2 '07 #3

Expert 100+
P: 534
Great, thanks for letting me know.
michael
Jan 2 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.