?
Solved

Properly calculating time differences

Posted on 2004-10-12
5
Medium Priority
?
555 Views
Last Modified: 2008-03-06
Before I get too involved in 'the wrong way' here, let me here some advice from you guys.

I have a time recording application that simply tracks time for my users.
I have two dtp items (dtpTime(0) & (1) - start and stop respectively).

Now, in my click event, I want to calculate the difference between the two.
However, if dtpTime(0) is valued at 12:00 AM, I simply want my total to be whatever is in dtpTime(1)

So, if a user sets
(0) = 8:00 AM
(1) = 8:30 AM

I want (I think) the return to be .5

There will be really rare occasions (and I haven't convinced myself yet to place it back in) where a timer function will allow these values to be set according to a stopwatch type recording for both start and stop values.
However, most values will probably be full, half or quarter hour (1, 1.25, 1.5, 1.75, etc)

Am I going about this the right way here?

The local db will probably store the actual Times (1:00PM and 1:30PM) as well as the difference (.5 or 30 mins).
But the master database is only concerned with the total (.5 or 30 mins).

I need to keep the range local in case the user ever wants to change the timeframe - but once submitted to the master, I have no need, nor will allow, these changes...

Any advice before I get my hands dirty? : )
0
Comment
Question by:sirbounty
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 8

Assisted Solution

by:mladenovicz
mladenovicz earned 248 total points
ID: 12288182
datediff("n","8:00", "8:30") will return you difference in minutes
datediff("n","8:00", "8:30")/60 will return you 0.5
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288241
Right, but am I going about the right method for storing this, or should I take a different approach?
Just looking for advice here really, not so much on the coding methods to be used - I'm familiar with most of them (I think) ;)_
0
 
LVL 16

Accepted Solution

by:
jimbobmcgee earned 252 total points
ID: 12288303
Before you start, execute the following statements (in the Immediate window, perhaps):

    MsgBox Now
    MsgBox Int(Now)
    MsgBox CDbl(Now)
    MsgBoc CLong(Now)
    MsgBox Now - Int(CDbl)
   
In VB, a date is a number.  Everything before the decimal point is the date, everything after is the time.

Now try:

    Dim n1 As Date
    Dim n2 As Date
    Dim i As Long

    n1 = Now

    For i = 1 To 500000000: Next i 'WAIT A LONG TIME

    n2 = Now

    MsgBox n1 & vbCrLf & n2 & vbCrLf & CDate(n2 - n1)

You should see the difference in time between n2 and n1...

HTH

J.
0
 
LVL 16

Expert Comment

by:jimbobmcgee
ID: 12288322
I guess what I'm saying above is; I'd imagine your database could store them in a date/time format.  If not, a double precision number field should do the trick...
0
 
LVL 67

Author Comment

by:sirbounty
ID: 12288355
Oh sure, I can store them in date/time format, and I like that cdate function - never used that one.

Guess that's it then.
Thanx for the info gentlemen.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month15 days, 8 hours left to enroll

741 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