Solved

Simple time conversion ?

Posted on 2006-11-17
14
215 Views
Last Modified: 2010-04-16
I have a small timeclock app. Heres' the scenario, I click a "Start Time" command button and it displays the current time. I click a "Stop Time" command button and it displays the current time, however, I also want it to compute the elapsed time and put that in another textbox...very simple. Problem is the computation is coming out in the format I wish it to.

Here is what the form looks like:

        Start Time      Stop Time
     13:45:00 pm  13:45:45 pm           45


I want it to look like this:

        Start Time      Stop Time
     13:45:00 pm  13:45:45 pm  00:00:45

I can't figure out how to get it in this format. I've included my code.

Thanks,
Blake


Private Sub cmdStart_Click()
    txtStartTime.Text = Format(Now, "hh:mm:dd am/pm")
End Sub
'
'
'
Private Sub cmdStop_Click()
    txtStopTime.Text = Format(Now, "hh:mm:ss am/pm")
    txtElapsedTime.Text = DateDiff("s", txtStartTime.Text, Format(Now, "hh:mm:ss"))
    txtElapsedTime.Text = Format(txtElapsedTime.Text, "hh:mm:ss")
End Sub

0
Comment
Question by:BlakeMcKenna
  • 5
  • 4
  • 4
  • +1
14 Comments
 
LVL 8

Expert Comment

by:YoungBonzi
ID: 17969528
Imports System.Globalization
Imports System.Threading

Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
txtElapsedTime.Text = txtElapsed.ToString("hh:mm tt")
0
 

Author Comment

by:BlakeMcKenna
ID: 17969540
No clue what your talking about!!!!!
0
 
LVL 8

Expert Comment

by:YoungBonzi
ID: 17969541
is this VBA or .NET?
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:BlakeMcKenna
ID: 17969580
It's VB 6
0
 
LVL 8

Expert Comment

by:YoungBonzi
ID: 17969587
Sorry, either way I wrote that wrong...it should be:

Dim ThisMoment As Date

Private Sub cmdStart_Click()
    Thread.CurrentThread.CurrentCulture = New CultureInfo("en-US")
    ThisMoment = Now
    txtStartTime.Text =  ThisMoment.toString("T")
End Sub
'
'
'
Private Sub cmdStop_Click()

    ThisMoment = Now
    txtStopTime.Text = ThisMoment.toString("T")
    txtElapsedTime.Text = DateDiff("s", txtStartTime.Text, txtStopTime.Text))
    txtElapsedTime.Text = txtElapsedTime.ToString("T")
End Sub
0
 
LVL 8

Expert Comment

by:YoungBonzi
ID: 17969591
Ah...sorry, I don't have access to VB6.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17969921
Try something like...

Option Explicit

Private startTime As Date
Private stopTime As Date
Private elapsed As Date

Private Sub cmdStart_Click()
    startTime = Now
    txtStartTime.Text = Format(startTime, "hh:mm:ss am/pm")
End Sub

Private Sub cmdStop_Click()
    stopTime = Now
    txtStopTime.Text = Format(stopTime, "hh:mm:ss am/pm")
   
    elapsed = stopTime - startTime
    txtElapsedTime.Text = Format(elapsed, "hh:mm:ss")
End Sub
0
 
LVL 16

Expert Comment

by:AlexNek
ID: 17972835
First ,try to save time as numeric value, don't forget about case 00:05 - 23:55 = 10 minutes.
Second, calculate the difference X in seconds and try to convert yourself. Hours= x/3600, minutes=(x % 3600)/60, seconds= x% 60
0
 

Author Comment

by:BlakeMcKenna
ID: 17976293
Thanks anyway, but I already found an answer. You can close this thread out if you like.

-Blake
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17976429
Since others posted solutions before you commented, you can either:

    (1) Assign points yourself to close the question.

    (2) Post your actual solution here in this thread, and then request a moderator PAQ/Refund your points here:
          http://www.experts-exchange.com/Community_Support/
0
 

Author Comment

by:BlakeMcKenna
ID: 17979802
How do I post it in Communit Support?
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 17979958
First post your solution here.

Then click on the community support link I gave and create a new question there.  In that question, ask for a PAQ/Refund because you solved the problem yourself.  They will only give your points back and close the question if they see that YOU have posted a solution here.  You can make the moderators job easier if you post a link back to this thread in your request.
0
 

Author Comment

by:BlakeMcKenna
ID: 17982762
Try this:

    txtElapsedTime.Text = Format$(Time - CDate(txtStartTime.Text), "hh:mm:ss")
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17982803
That'll work.  It's essentially the same as my code without using any intermediate variables.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 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