Home » excel » How can I reverse the Excel time function to hour, minute and second?

How can I reverse the Excel time function to hour, minute and second?

Posted by: admin May 14, 2020 Leave a comment

Questions:

In Excel I use the following function

Time( hour, minute, second )

And it appears in the following format

11:07:27 AM

However when I treat excel as an ODBC data source and use getString to retrieve the value, it comes out something like

0.45856481481

How can I reverse this back to hours, minutes and seconds?

How to&Answers:

For starters, see the SO question/answer for Excel parsing (xls) date error for an explanation of date time formats in Excel; this will explain where that number you are seeing is coming from. Your problem is just a variation; numbers to the right of a decimal are an indicator of time measured as a fraction of a day.

I am going to assume you are using Java (based on the clues in your post), though your post isn’t tagged with a programming language.

You should not use getString() to return a date value because this method simply returns the string representation of the underlying data (in this case, the number); you should use getDate() instead, which will translate the number into a date.