Solved

Simple time conversion ?

Posted on 2006-11-17
14
213 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
A short article about problems I had with the new location API and permissions in Marshmallow
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…

911 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

16 Experts available now in Live!

Get 1:1 Help Now