473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

How to cast varchar into timestamp in postgres

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
3 14871
michaelb
534 Expert 512MB
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
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
michaelb
534 Expert 512MB
Great, thanks for letting me know.
michael
Jan 2 '07 #4

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

Similar topics

1
by: George Develekos | last post by:
I need to import into mysql data from DB2. One of the DB2 table columns is of the TIMESTAMP type, which, unlike its MySQL counterpart, supports fractions of a second, up to 6 digits, i.e. it is of...
2
by: Jitender Kumar C | last post by:
Hi, I want to extract date part (mm/dd/yy or any other date format) of Timestamp in postgreSQL. Can anyone help me out how I can proceed?. Regards, Ch.V.J. Kumar |Associate Consultant |...
2
by: Campano, Troy | last post by:
Hi, I'm trying to compare a timestamp to current_timestamp but I'm having trouble. I want to compare just the date piece of my timestamp column to just the date piece of current_timestamp. ...
6
by: Jim C. Nasby | last post by:
Is there any reason why there isn't a predefined cast to go from a timestamp to a varchar? Is there a reason not to add one? -- Jim C. Nasby, Database Consultant jim@nasby.net...
4
by: T.M. | last post by:
What is the correct syntax for querying the first 20 characters of a memo field? I'm trying to SELECT CAST (varchar(20) fieldname) as newfieldname and i get a bunch of errors Can someone...
2
by: T.M. | last post by:
What is the correct syntax for querying the first 20 characters of a memo field? I'm trying to SELECT CAST (varchar(20) fieldname) as newfieldname and i get a bunch of errors Can someone...
5
by: whitsey | last post by:
Hi, I can easily convert a TIMESTAMP to a DATE which will give me results in the format 'DD/MM/YYYY' however, what I want to do is convert the TIMESTAMP to just 'MM/YYYY' or even better...
0
by: robykeys82 | last post by:
Hi! I'm an Italian user of PostGres and I'm having some trouble! I hope you can help me! I'm trying to migrate the db content from SQL SERVER 2005 to PostGreSQL. Everything works ok except for the...
8
by: BusterKarmul | last post by:
Hello, Is it possible to determine the Min and Max timestamp intervals for records as they are inserted (SQL Server 2005)? The table accepts inserts only (no updates) and produces this output: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.