Solved

Convert decimal to time

Posted on 2004-04-08
5
1,159 Views
Last Modified: 2008-02-01
Hello All

I want to be able to grab a number, anything from 0.016666 to 86399.999999
and convert it to a time

For example:

0.50 = 30 seconds or 00:00:30 and 00:30
1.50 = 1 minute, 30 seconds or 00:01:30 and 01:30
197.50 = 3 hours, 17 minutes, 30 seconds or 03:17:30 and 197:30

I can do the calculations by hand (on a calculator) but can't get my head around the code or the formatting of the end figure.

Can someone please help

Dahquim
0
Comment
Question by:dahquim
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
mmusante earned 50 total points
Comment Utility
If the number N is expressed in minutes ...

format(N/1440,"hh:nn:ss")
0
 

Author Comment

by:dahquim
Comment Utility
Thanks for the reply
This works great, i feel so dumb for not realising this.

However, how do i do the second part

so 03:17:30 = 197:30

Would it be just  case of taking the hours multipling by 60 and then adding the minutes?

Thanks for the help

Dahquim
0
 

Author Comment

by:dahquim
Comment Utility
I have sorted it, thanks for the help.

Dahquim
0
 
LVL 6

Expert Comment

by:mmusante
Comment Utility
Yas for Min:Secs format, to have back the minutes-with-decimals format try this ...

cdbl(#03:17:30#)*1440
0
 
LVL 44

Expert Comment

by:Arthur_Wood
Comment Utility
try this:

1) convert the number to Seconds

Dim Seconds As Long
Dim Number As Double

Number = Text1.Text

Seconds = Number * 60

2) then conver the number of seconds into Days, Hours, minutes and seconds in that order:
Dim Days As Long
Dim Hours As Long
Dim Minutes As Long

Days = Fix(Seconds / 86400) '86400 seconds in 1 day)
Hours = Fix((Seconds - Days * 86400) / 3600) ' 3600 Seconds in 1 Hour
Minutes = Fix((Seconds - Days * 86400 - Hours * 3600) / 60)
Seconds = Seconds - Days * 86400 - Hours * 3600 - Minutes * 60
Text2 = Days
Text3 = Hours
Text4 = Minutes
Text5 = Seconds


AW
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now