Solved

Convert decimal to time

Posted on 2004-04-08
5
1,166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 6

Accepted Solution

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

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

Author Comment

by:dahquim
ID: 10783112
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
ID: 10783195
I have sorted it, thanks for the help.

Dahquim
0
 
LVL 6

Expert Comment

by:mmusante
ID: 10783212
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
ID: 10783226
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

705 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