Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Simple time conversion ?

Posted on 2006-11-17
14
Medium Priority
?
220 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
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!

 

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 86

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 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 1000 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 86

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

Industry Leaders: 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

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Introduction to Processes

885 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