I need to convert a double to a date format of h:mm:ss then ultimately to a string. I can do it manually, but I'm wondering if there is a built in function that would do it.
any help is greatly appriciated.
kevin
Printable View
I need to convert a double to a date format of h:mm:ss then ultimately to a string. I can do it manually, but I'm wondering if there is a built in function that would do it.
any help is greatly appriciated.
kevin
Hi kebo!
Try this !
VB Code:
Dim dt As Date dt.FromOADate(MyDouble)
Zak
thanks zak...
not sure if that's what I'm looking for (maybe it is and I'm not using it right)
I have double that represents an amount of time in minutes and I need to convert it to h:mm:ss format, not neccessarily to time (bad phasing on my part).
For example to convert 2.92 minutes, FromOADate(2.92) = 12:00:00 AM, but I need it to return 0:02:55
Any suggestions?
kevin
I would usually suggest using Date.ParseExact().toString("h:mm:ss") but in since you're not using seconds I beleive you're SOL. What is the Function you're using?
Emm i see....
I also miss write the function dt.FromOADate(MyDouble)
Try instead
Dim dt As Date
dt = Date.FromOADate(MyDouble)
I've do some test and
Date.FromOADate(1.5) is equal to #12/31/1899 12:00:00 PM#
And
New Date is equal to #12/30/1899 12:00:00 AM#
So Adding 1.5 add 1 day and a half. And with dt.Hour and dt.Minute and dt.Second you may get your Hour as you wish !!
Hope i'm clear enough
Zak
thanks for the responses
wild_bill:
this is what I'm doing now
Zak:VB Code:
Private Function TimeConvert(ByVal t As Double) As String Dim h As Integer = CType(t / 60, Integer) t -= h * 60 Dim m As Integer = CInt(Fix(t)) t -= m Dim s As Double = 60 * t Return Microsoft.VisualBasic.Format(h, "#0:") & _ Microsoft.VisualBasic.Format(m, "00:") & _ Microsoft.VisualBasic.Format(s, "00.0") End Function
you kinda lost me
kevin
Sorry will try to do better next time :blush:Quote:
Originally Posted by kebo
it's all good... thanks for the input nonetheless
kevin
VB Code:
Dim numMinutes As Double Dim myTimeString As String = New TimeSpan(0, 0, Convert.ToInt32(numMinutes)).ToString()
Sorry. Reread your previous posts and I realise its not that simple if you want to use fractional minutes.VB Code:
Dim totalMinutes As Double ' = 2.92 Dim minutes As Integer = CInt(Math.Floor(totalMinutes)) Dim seconds As Integer = CInt((totalMinutes - minutes) * 60) Dim myTime As New TimeSpan(0, minutes, seconds) Dim myTimeString As String = String.Format("{0}:{1:00}:{2:00}", myTime.Hours, myTime.Minutes, myTime.Seconds)
well done jmcilhinney
thanks
kevin