Results 1 to 8 of 8

Thread: [RESOLVED] Convert Hours Mintues and seconds into decimal

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Resolved [RESOLVED] Convert Hours Mintues and seconds into decimal

    If I have 5:32:43 (5 hours 32 Minutes and 43 Seconds) is there a function to turn this into decimal (5.5453)

    Thanks

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Re: Convert Hours Mintues and seconds into decimal

    That just seems to put it in the format 5:32:43? Is there a way to make it change it to decimal?

  3. #3
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Convert Hours Mintues and seconds into decimal

    .5453 is the decimal fraction equilivalent of :32:43?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Convert Hours Mintues and seconds into decimal

    Code:
    Value = CDbl(CDate("5:32:43")) * 24
    Value will be 5.54527777777778

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Re: Convert Hours Mintues and seconds into decimal

    yes it is

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jul 2005
    Posts
    150

    Re: Convert Hours Mintues and seconds into decimal

    THank you CVMichael thats what I was looking for

  7. #7
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: [RESOLVED] Convert Hours Mintues and seconds into decimal

    Welcome...

    Don't forget to mark the tread as Resolved from Thread Tools Menu

    [Edit]
    Ah... I was slow on that... you already did

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: [RESOLVED] Convert Hours Mintues and seconds into decimal

    Just a note:

    The Date data type is actually stored as a double, so the previous you can even do as:
    Code:
    Value = #5:32:43# * 24
    If you want to add a day (for example) to the date, you can do:
    Code:
    Tomorow = Date + 1
    To add a todays date to a time value:
    Code:
    TodaysDateAndTime = Date + #5:32:43#
    To find out how many days are between 2 dates:
    Code:
    Days = #2/1/2006# - #2/20/2006#
    Etc.

    So, since it's stored as a double, you can do mathematical calculations with it...
    where
    1 is one day
    1 / 24 = 4.16666666666667E-02 is one hour
    1 / 24 / 60 = 6.94444444444444E-04 is one minute
    and finally
    1 / 24 / 60 / 60 = 1.15740740740741E-05 is one second

    So if you want to add one second to a time: #5:32:43#
    You do
    Code:
    Debug.Print #5:32:43# + 1.15740740740741E-05
    
    Returns: 5:32:44 AM
    I know, I know... more than you asked for... sorry...

    But it's good to know

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