Solved

Simple time conversion ?

Posted on 2006-11-17
14
214 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C# code editing and collaboration 3 113
Path to Python 9 118
Adoquery sql  left join does not work 25 90
Advice in Xamarin 21 79
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.
Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
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 …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

773 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