Wrox Programmer Forums
|
Access Discussion of Microsoft Access database design and programming. See also the forums for Access ASP and Access VBA.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 11th, 2003, 02:33 PM
Authorized User
 
Join Date: Jun 2003
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi J

Well if you always assume that the End Time is always after the Start Time, you could had a day to the End Time if it's smaller than the Start Time. It will look like this:
SELECT
  Table1.time_field1 AS [Start Time],
  IIF(Table1.time_field2 < Table1.time_field1, Table1.time_field2 + TimeSerial(24,0,0),Table1.time_field2) AS [End Time],
  Table1.rate_per_hour,
  DateDiff('s',[time_field1],[End Time])/3600 AS TimeDifference
  DateDiff('s',[time_field1],[End Time])/3600 * [rate_per_hour] AS Payroll
FROM Table1;

This solution will correct your last problem, but what will you do with this case:
timefield1START timefield2END timeDifference
18:51 18:51 24:00 (the next day)
18:51 18:51 00:00 (the same day)

Stéphane Lajoie
 
Old August 11th, 2003, 04:19 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Default

J

If you need to include days in your calculations then include them in your data - it will save you soooooo much trouble in the long run.

I made this mistake in an engineers working time logging database. Two years and many pages of data validation code later, I'm still not convinced that I'm always getting the correct data.


Brian Skelton
Braxis Computer Services Ltd.
 
Old August 11th, 2003, 05:14 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Hi J,

Stephane and Brian probably have the final word for you, but...well...I was playing around and here is the "function call from a query" version, just for kicks:

This goes in a standard module and does a bunch of conversions:

Function ConvertToDouble(TimeDifference)
    TimeDifference = CDate(TimeDifference)
    ConvertToDouble = CDbl(TimeDifference) * 24
End Function

Here's the SQL:

SELECT
    Table1.time_field1 AS [Start Time],
    Table1.time_field2 AS [End Time],
    ConvertToDouble(Format([time_field1]-1-[time_field2],"Short
         Time")) AS [Time Difference]
FROM Table1;

Two business rules:
   a) no one works over 24 hours without clocking out (seems
      reasonable)
   b) all hours are recorded in 15 minute intervals (or else
      format the return value to the number of decimals of your
      choice)

Seems to work. Heres some data:

Start Time End Time Time Difference
18:45 00:45 6
06:00 12:00 6
04:30 13:00 8.5
19:00 00:45 5.75
12:00 15:00 3
20:00 01:30 5.5
17:15 18:15 1

Bob
 
Old August 12th, 2003, 10:24 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 174
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm sure you all have this working by now, but while looking for something else, I ran across this KB Article:
http://support.microsoft.com/default...b;en-us;210604

Towards the bottom is discusses TimeCard calculations. Just an FYI.

Beth
 
Old August 12th, 2003, 11:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,151
Thanks: 2
Thanked 14 Times in 14 Posts
Send a message via ICQ to SerranoG Send a message via AIM to SerranoG
Default

Quote:
quote:Originally posted by jobalistic
timefield1 timefield2 timeDifference
10:00 11:30 1:30

Thus, I need to multiply this difference by the 5 dollars per hr rate which would be 6.5

When I use your equation for this example the result does not become 1:30 but instead goes to 1.5 since 30 minutes is half the hr. Thus I would be multiplying it by 1.5, NOT 1.30.

Is there anyway that the time difference be converted to as a number, as is? (example for 1:30, it converts to 1.30 and not 1.5 hrs)
Now you're losing me. The time difference 1:30 means "one hour and thirty minutes." To translate that into hours is not 1.3 hours; it is 1.5 hours. So 1:30 should not be converting to 1.3 because 1.3 is approximately one hour and twenty minutes.

Greg Serrano
Michigan Dept. of Environmental Quality, Air Quality Division
 
Old August 24th, 2007, 10:43 AM
Registered User
 
Join Date: Aug 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I realize this is an old thread, but thanks to those with the answers. This one was simple and great help.

 
Old February 22nd, 2013, 12:38 PM
Registered User
 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Better late than never

Hey,

The solution:

(24-([Formulieren]![perso-uren-overzicht form]![beginuur]*24))+(0+([Formulieren]![perso-uren-overzicht form]![einduur]*24))

I now is in Dutch but:

Change 'formulier to Forms'
and [perso-uren-overzicht form]![beginuur]* [to your fieldname]

This give the exact respons

Hope you can use this one

grds
 
Old February 22nd, 2013, 12:40 PM
Registered User
 
Join Date: Feb 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

by the way:
beginuur = start-time
einduur = end-time





Similar Threads
Thread Thread Starter Forum Replies Last Post
getting the first non-zero number in a field elygp SQL Language 3 March 27th, 2008 03:57 AM
convert number into words on acces form superparim Wrox Book Feedback 0 September 19th, 2005 01:55 PM
Convert date to number samirz10 Access 1 July 22nd, 2005 03:04 PM
Convert to a number ticktack Classic ASP Basics 4 February 9th, 2004 05:31 AM
How can i convert english numbers to arabic number zahidpervaiz Classic ASP Databases 0 December 30th, 2003 06:51 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.