473,774 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB Function to convert Decimal to Elapsed Time [h]:mm:ss (like in Excel)?

yarbrough40
320 Contributor
Can anyone help me to display a Decimal (or double) to elapsed time [h]:mm:ss (hours:minutes: seconds)using vb.net?
example:
if you were to type "1.346666666666 67" into a cell in Excel then choose Custom Format [h]:mm:ss The result is an elapsed time of "32:19:12". Using the OADate function only runs on a 24 hour clock so this does not work for longer durations unfortunately.. .
Jun 21 '09 #1
4 15323
yarbrough40
320 Contributor
ok so I figured it out with math I don't normally have patience for so in case anyone cares... I created these two simple functions produce the result


Expand|Select|Wrap|Line Numbers
  1. Private Function ElapsedTime(ByVal DNum As Double) As String
  2.  
  3.         Dim hh, mm, ss As Integer
  4.         Dim _hh, _mm, _ss As Double
  5.  
  6.         _hh = DNum * 24
  7.         hh = Math.Truncate(_hh)
  8.  
  9.         _mm = DecimalPart(_hh) * 60
  10.         mm = Math.Truncate(_mm)
  11.  
  12.         _ss = DecimalPart(_mm) * 60
  13.         ss = Math.Truncate(_ss)
  14.  
  15.  
  16.         ElapsedTime = hh & ":" & mm & ":" & ss
  17.  
  18.         Return ElapsedTime
  19.     End Function
  20.  

Expand|Select|Wrap|Line Numbers
  1. Private Function DecimalPart(ByVal nbr As Decimal) As Double
  2.  
  3.         Dim wholePart, fractionalPart As Decimal
  4.  
  5.         wholePart = Math.Truncate(nbr)
  6.         fractionalPart = nbr - wholePart
  7.  
  8.         DecimalPart = fractionalPart
  9.         Return DecimalPart
  10.  
  11.     End Function
  12.  
Jun 22 '09 #2
iam_clint
1,208 Recognized Expert Top Contributor
You can use a stopwatch to do elapsed time...

Can you explain better what you are actually trying to accomplish
Jun 22 '09 #3
iam_clint
1,208 Recognized Expert Top Contributor
i'm sure there is a better way to accomplish what you are actually trying to get can you get a little more detail on what you are doing
Jun 22 '09 #4
yarbrough40
320 Contributor
I litterally have a database with elapsed times (in double format) so I have no need to use a stopwatch since I already have the elapsed times. I simply need to display those elapsed times on the page in the format of [h]:mm:ss

the functions I wrote do work. if u have a better suggestion that would be excellent, however I don't believe there is an existing function for this...

example: 1.3466666666666 7
A) multiply the entire decimal by 24 (the whole part of the answer is hours) = 32
B) multiply the entire decimal from (A) and multiply it by 60(the whole part is the minutes) = 19
C) multiply the entire decimal from (B) and multiply it by 60(the whole part is the seconds) = 12

put em all together separated by ":" and there u have it
"32:19:12"
Jun 22 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
2488
by: D. Shane Fowlkes | last post by:
Here's a good one. I've been using an Excel spreadsheet for the past couple of years to calculate a file's Estimated Download Time based off of a solid 50kbs connection (dial up). This is for a downloads page such as: http://www.drpt.virginia.gov/downloads/selectedcat.aspx?ID=12 The formula is basically this: =(((C4*1000*8)/50000)/84600)*1.1 (Estimate is calculated on a modem dial up connection of 50Kbs and transfer
2
6942
by: Robert Brown | last post by:
Hi all. I have written a program that transfers data via FTP. I can calculate the rough amount of time left. I get a value such as 70.83 seconds left for instance. What I want to do is to change this to hh:mm:ss format. Obviously, VB.NET doesn't seem to want to convert this unless it is already a DATETIME cast.
14
4101
by: Michael Barrido | last post by:
I have this for example: Dim iSeconds as int32 = 3600 '3600 seconds is one hour How do i convert it to "01:00:00" ? Please help. Thanks in advance!
5
10600
by: kpp9c | last post by:
Hi, I was looking at python & datetime and hoping that it would already have a method/func to translate time formats. I need to translate seconds to hh:mm:ss.ms and vice versa and would like the ability to do some basic arithmetic in these formats. I think that there just has to be a package or module out there that already does this with reasonable speed and accuracy.
5
19188
nirmalsingh
by: nirmalsingh | last post by:
i am getting date format in string as 30-11-2006 05:59:44 PM . i want to convert in the format of yyyy-mm-dd hh:mm:ss to sore it in mysql database. Help me with sample coding plz..
1
2687
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i want to generate a an excell sheet of that table but here i want the time to be like mm:ss but not hh:mm:ss examle the length of song sweet dreams is 01:12:35 now i want this to be shown as 72:35 how is there any procedure to convert directly in...
1
2168
seshu
by: seshu | last post by:
Hi every body to morning my cousine has show his application and also his live db in that to sav the length of all the voice files he has saved in time format ie he took the datatype of time now i want to generate a an excell sheet of that table but here i want the time to be like mm:ss but not hh:mm:ss examle the length of song sweet dreams is 01:12:35 now i want this to be shown as 72:35 how is there any procedure to convert directly in...
5
27263
by: lofty | last post by:
Hi, I'm building a time report system for work and I want to show the total hours and minutes a project have taken but can't get it to work ... I have a database (MySQL) in one table I have the date in one colum and the time in one colum. The date i formated like this YYYY-MM-DD and set to date. And the TIME is like this HH:mm:ss. My code looks like this right now... <?php $sql="select p.id, p.date, p.time
5
32401
by: sudip77 | last post by:
Hi, I have an user input variable called @stop_time which takes input in the format of HH:MM:SS. I need to convert it into seconds only. How can I do that? Can anyone help please?
0
9621
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10040
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7463
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.