Results 1 to 11 of 11

Thread: is there a function to convert a double to date? [resolved]

  1. #1

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Resolved 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

  2. #2
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: is there a function to convert a double to date?

    Hi kebo!

    Try this !
    VB Code:
    1. Dim dt As Date
    2.     dt.FromOADate(MyDouble)

    Zak

  3. #3

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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

  4. #4
    Code Monkey wild_bill's Avatar
    Join Date
    Mar 2005
    Location
    Montana
    Posts
    2,993

    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?

  5. #5
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    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.

  6. #6

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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:
    1. Private Function TimeConvert(ByVal t As Double) As String
    2.  
    3.         Dim h As Integer = CType(t / 60, Integer)
    4.         t -= h * 60
    5.  
    6.         Dim m As Integer = CInt(Fix(t))
    7.         t -= m
    8.  
    9.         Dim s As Double = 60 * t
    10.  
    11.         Return Microsoft.VisualBasic.Format(h, "#0:") & _
    12.                Microsoft.VisualBasic.Format(m, "00:") & _
    13.                Microsoft.VisualBasic.Format(s, "00.0")
    14.  
    15.     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

  7. #7
    Frenzied Member Zakary's Avatar
    Join Date
    Mar 2005
    Location
    Canada, Quebec, Montreal
    Posts
    1,654

    Re: is there a function to convert a double to date?

    Quote Originally Posted by kebo
    Zak:
    you kinda lost me
    kevin
    Sorry will try to do better next time

  8. #8

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: is there a function to convert a double to date?

    VB Code:
    1. Dim numMinutes As Double
    2.         Dim myTimeString As String = New TimeSpan(0, 0, Convert.ToInt32(numMinutes)).ToString()
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  10. #10
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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:
    1. Dim totalMinutes As Double ' = 2.92
    2.         Dim minutes As Integer = CInt(Math.Floor(totalMinutes))
    3.         Dim seconds As Integer = CInt((totalMinutes - minutes) * 60)
    4.         Dim myTime As New TimeSpan(0, minutes, seconds)
    5.         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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  11. #11

    Thread Starter
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    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
  •  



Click Here to Expand Forum to Full Width