Hadi
Hadi

Reputation: 37313

Convert Time stored as integer to datetime

I have time stored as integer in a database

Example: 11325 means 01:13:25

i am trying to make a function to do this work

i used the following code:

 Public Function GetTimeFromInt(ByVal intTime As Integer) As DateTime


    Dim strTemp As String = intTime.ToString("D6")

    strTemp = strTemp.Insert(4, ":").Insert(2, ":")

    Dim dtResult As DateTime = Date.ParseExact(strTemp, "HH:mm:ss", New System.Globalization.CultureInfo("en-GB"), Globalization.DateTimeStyles.None)

    Return dtResult


End Function

And it is working fine. But i want to now if there is a way to do this using string formatting maybe like int.ToString("nn:nn:nn")

Upvotes: 1

Views: 1938

Answers (1)

Sjoerd
Sjoerd

Reputation: 75578

Yes:

123456.ToString("00:00:00")

This will give 12:34:56.

Upvotes: 4

Related Questions