How to Convert Standard Time Into Decimal Time With Visual Basic

Written by selma leathem
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Convert Standard Time Into Decimal Time With Visual Basic
Convert to Decimal Time (time. image by Alexander Lukyanov from

Standard time can be converted into decimal time using Visual Basic's built-in functions. Visual Basic works with both the date and time together. It is not possible to separate the date and time into two different independent values that can be manipulated separately. This means there is no single built-in function that will perform the task of converting the time, exclusively. However, it is still possible to do the conversion using Visual Basic's built-in functions in combination with a single line of computation.

Skill level:

Other People Are Reading


  1. 1

    Store the time that you want in a variable. Visual Basic has a DateTime Data type which is used to represent Date and Time values, as is described in "Murach's Visual Basic 2008." Use the Visual Basic's Dim command to declare the time as follows: Dim DateOne As DateTime = #3:15:30 AM# The Date and Time are represented as a pair, which means if you don't provide a date or time Visual Basic will substitute reference values representing the smallest date or time. Visual Basic's starting date is 12:00 AM January 1st 0001. For example, if you printed the above initialised variable to the screen, you would get '1/01/0001 3:15:30'.

  2. 2

    Convert the DateTime variable into a decimal date and time using the built-in function ToOADate(). This built in function will convert the time to a double data type. Visit for more information. For example, the code to convert a DateTime variable into a double is: Dim ADate As DateTime = #3:15:30 AM# Dim DbleTime As Double = ADate.ToOADate() Console.WriteLine(DbleTime) This produces the following decimal date and time: '0.1357638...'

  3. 3

    Extract the standard time from this floating value by multiplying the value to the right of the decimal point by 24 with the following code:
    DbleTime *24 The result for this example should be 3.25833.

Tips and warnings

  • If you also want to extract the minutes and seconds in decimal format, then multiply the number to the right of the decimal in the time by 60 to get the minutes and multiply the number to the right of the decimal in the minutes by 3600 to get the seconds. As an alternative, Visual Basic provides the DatePart() function that extracts the hour, minutes and seconds, which can be converted into decimal format as follows:
  • Dim TheMinute As Double = CDbl(DatePart(DateInterval.Minute, DateOne)) / 60.0
  • Dim TheSecond As Double = CDbl(DatePart(DateInterval.Second, DateOne)) / 3600.0

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.