sandrao said:
How would you go about to round up the time to the nearest 15 minutes.
In this payroll program I have a StartTime and a EndTime. these run
off the comuter clock and record the exact time of start and end.
Start could be 8:05 and end could be 17:05. How can I have the time
rounded up to the nearest 15 minutes.
Using my duration functions from the following thread:
http://groups.google.com/group/microsoft.public.access/browse_frm/thread/be7e101c5176ebd8
Note: If the person is going to punch in for a period that is longer
than 68 years another method should be used
.
Available functions:
DDHHNNSS2Seconds(strTime As String)
Seconds2DDHHNNSS(lngTotalSeconds As Long)
AddDDHHNNSS(strTime1 As String, strTime2 As String)
SubtractDDHHNNSS2Seconds(strTime1 As String, strTime2 As String)
Note: The functions could also be changed to omit full days and use
floating point minutes instead to obviate the conversion to minutes
15 minute Ceiling: -Abs(-X * 15) / 15, where x is in minutes
Steps:
1. Get the start and stop times into the expected format
E.g.:
"00:" & Format("8:05", "hh\:nn\:ss") => 00:08:05:00
"00:" & Format("17:05", "hh\:nn\:ss") => 00:17:05:00
2. Convert to seconds, then minutes
E.g.:
DDHHNNSS2Seconds("00:" & Format("8:05", "hh\:nn\:ss")) => 29100 seconds
DDHHNNSS2Seconds("00:" & Format("17:05", "hh\:nn\:ss")) => 61500 seconds
SubtractDDHHNNSS2Seconds("00:" & Format("17:05", "hh\:nn\:ss"), "00:" &
Format("8:05", "hh\:nn\:ss")) / 60 => 540 minutes
3. Apply the Ceiling function
-Int(-SubtractDDHHNNSS2Seconds("00:" & Format("17:05", "hh\:nn\:ss"),
"00:" & Format("8:05", "hh\:nn\:ss")) / 4) / 15 => 540 minutes
4. Convert to seconds
-Int(-SubtractDDHHNNSS2Seconds("00:" & Format("17:05", "hh\:nn\:ss"),
"00:" & Format("8:05", "hh\:nn\:ss")) / 4) * 4 => 32400
5. Convert back to a time string that indicates the duration
Seconds2DDHHNNSS(-Int(-SubtractDDHHNNSS2Seconds("00:" & Format("17:05",
"hh\:nn\:ss"), "00:" & Format("8:05", "hh\:nn\:ss")) / 4) * 4) =>
00:09:00:00
I.e., 0 Days, 9 Hours, 0 Minutes, 0 Seconds
In using that expression in a query, "8:05" and "17:05" would be
replaced by the table field names. AddDDHHNNSS() could be used
repeatedly to add together a set of durations, or it could be changed to
accept an array of durations. Taking account of days is a relatively
clean way to account for both durations crossing midnight and adding
durations whose total is greater than or equal to 24 hours. Hint: You
can use the DateDiff() function to get the number of minutes in a
duration based on start and stop Date/Time fields using the complete
Date/Time field rather than using just the hours and minutes from a time
ticket.
Other posters here, such as Douglas Steele, have posted somewhat similar
solutions.
Post back if you need more help.
James A. Fortune
(e-mail address removed)