|
-
Jul 26th, 2005, 11:08 AM
#1
is there a function to convert a double to date? [resolved]
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
Last edited by kebo; Jul 26th, 2005 at 07:25 PM.
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Jul 26th, 2005, 11:31 AM
#2
Re: is there a function to convert a double to date?
Hi kebo!
Try this !
VB Code:
Dim dt As Date
dt.FromOADate(MyDouble)
Zak
-
Jul 26th, 2005, 12:12 PM
#3
Re: is there a function to convert a double to date?
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
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Jul 26th, 2005, 12:18 PM
#4
Re: is there a function to convert a double to date?
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?
-
Jul 26th, 2005, 12:36 PM
#5
Re: is there a function to convert a double to date?
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
Last edited by Zakary; Jul 26th, 2005 at 12:42 PM.
-
Jul 26th, 2005, 01:06 PM
#6
Re: is there a function to convert a double to date?
thanks for the responses
wild_bill:
this is what I'm doing now
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
Zak:
you kinda lost me
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Jul 26th, 2005, 01:19 PM
#7
Re: is there a function to convert a double to date?
 Originally Posted by kebo
Zak:
you kinda lost me
kevin
Sorry will try to do better next time
-
Jul 26th, 2005, 01:41 PM
#8
Re: is there a function to convert a double to date?
it's all good... thanks for the input nonetheless
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
-
Jul 26th, 2005, 06:53 PM
#9
Re: is there a function to convert a double to date?
VB Code:
Dim numMinutes As Double
Dim myTimeString As String = New TimeSpan(0, 0, Convert.ToInt32(numMinutes)).ToString()
-
Jul 26th, 2005, 07:10 PM
#10
Re: is there a function to convert a double to date?
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)
Last edited by jmcilhinney; Jul 26th, 2005 at 07:14 PM.
-
Jul 26th, 2005, 07:24 PM
#11
Re: is there a function to convert a double to date?
well done jmcilhinney
thanks
kevin
Process control doesn't give you good quality, it gives you consistent quality.
Good quality comes from consistently doing the right things.
Vague general questions have vague general answers. A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.
______________________________ Last edited by kebo : Now. Reason: superfluous typo's
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|