Solved

Simple time conversion ?

Posted on 2006-11-17
14
212 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
 

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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

RIA (Rich Internet Application) tools are interactive internet applications which have many of the characteristics of desktop applications. The RIA tools typically deliver output either by the way of a site-specific browser or via browser plug-in. T…
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

13 Experts available now in Live!

Get 1:1 Help Now