I want to fetch current server time in DB2 in the format HH:MM:SS:M
e.g. 21:05:38:7
How should I modify below query to achieve it:
SELECT current time FROM sysibm.sysdummy1
Thanks for reading!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Times, Dates, Timestamps are all data types that DB2 stores in some internal data representation form. It is only when you ask to see it, SELECT MyTime FROM MyTable, that DB2 is forced to convert those bytes into something a human can read. DB2 will use the locale settings to convert a DATE to eg 2012-03-17, 17/03/2012, …
This can be great fun when you develop on a central DB2 database and your customers are from the UK, the USA, France, India, …. They will all complain that the dates are malformed. You should always think DB2 will do it wrong and do the formatting yourself.
These things are best done by the reporting tool you use. So you can use the right format for your user and you don’t have to settle for whatever the locale settings on the DB2 database server are.
In some cases you will have to do the formatting in SQL. Have you read the article Amit Bhargava referred to? Near the end the author creates a function ts_fmt that can handle a few formats and that can easily be extended with whatever formatting you need: Just add this code right before the ELSE part.