I have a column that comes into my SQL database as a varchar(10), but looks like HH:MM:SS. The column name is runTime.
I need to convert that column to seconds and do some calculations with it and another colunm called totalItems. totalItems is an int data type. An example of one calculation would be:
totalItems/runTime
So, it appears as though I need to convert runTime to a decimal, and then use it in the calculation, but when I can’t do that without first converting the time to seconds, or I get an error (due to the “:”).
So, how can I possibly convert the sessionRunTime into seconds first, and then convert those seconds to a decimal data type, then do the calculation from there? One example might be 59222 totalItems and 04:15:17 for runTime.
If there’s a better way to handle this, I’m certainly open to that as well. Thanks!
So long as the hours portion doesn’t match or exceed 24, you can
convertto a datetime and use the built in functions to work out how long the time is in seconds:If you need to do maths with this result, and the other value is an
int, then multiple one or other of the values by1.0to force the maths to be done asfloats, if that’s required.