473,587 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subtracting time past midnight

I want to be able to subtract two time fields, one starting before
midnight and the other past midnight. example:
starttime 23:00 and endtime 01:10
The answer is 1:10.
How can I do this with all times on the 24 hour clock?
Nov 13 '05 #1
4 6135
On Mon, 29 Nov 2004 05:22:25 GMT, Robert Schoenert <rs********@min dspring.com>
wrote:
I want to be able to subtract two time fields, one starting before
midnight and the other past midnight. example:
starttime 23:00 and endtime 01:10
The answer is 1:10.
How can I do this with all times on the 24 hour clock?


Easy. If you always know what the time direction should be, then any negative
number result needs to have 1 day added to it.

Public Function TimeDiff( _
StartTime As Variant, _
EndTime As Variant _
) As Variant
varTimeDiff As Variant

varTimeDiff = EndTime - StartTime
If varTimeDiff < 1 Then
varTimeDiff = varTimeDiff + 1.0 ' 1.0 = 1 day
End If

' CVDate in case data type is changed during computation.
TimeDiff = CVDate(varTimeD iff)
End Function
Nov 13 '05 #2
Add a day to the EndTime if it is less than the StartTime:

Minutes: DateDiff("n", [StartTime], [EndTime] + IIf([EndTime] <
[StartTime]), 1, 0))

For instructions on formatting that as hours and minutes, see:
Calculating elapsed time
at:
http://members.iinet.net.au/~allenbrowne/casu-13.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Robert Schoenert" <rs********@min dspring.com> wrote in message
news:hv******** *************** *********@4ax.c om...
I want to be able to subtract two time fields, one starting before
midnight and the other past midnight. example:
starttime 23:00 and endtime 01:10
The answer is 1:10.
How can I do this with all times on the 24 hour clock?

Nov 13 '05 #3
Steve Jorgensen wrote:
If varTimeDiff < 1 Then


I'd change that to a while loop, to catch the realy slow ones :-)
--
This sig left intentionally blank
Nov 13 '05 #4
On Mon, 29 Nov 2004 08:29:58 +0000, Trevor Best <no****@besty.o rg.uk> wrote:
Steve Jorgensen wrote:
If varTimeDiff < 1 Then


I'd change that to a while loop, to catch the realy slow ones :-)


If there's no date information, then the diff could never be greater than 1
day. If there is date information, then we could simply subtract, and
multiply by 24 to get a result in fractional hours, and the negative should
never come up.
Nov 13 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3589
by: Kevin Lin | last post by:
Hi, I'm trying to come up with a function using PHP/MySQL (preferably a PHP only solution) to find the next time that matches a particular pattern, where the pattern is a combination of values or wildcards for minute, hour, day, weekday, month (like a predictive version of Unix's cron.) So, for example, I might ask for the next time that...
4
2678
by: richardkreidl | last post by:
How would I check to see if the current time(military format) is greater then 07:30AM and the day of the week is Monday-Friday. Pseudo code: If Current_Time > 07:30AM and Current_Day = Monday or Current_Day = Tuesday _ or Current_Day = Wednesday or Current_Day = Thursday or Current_Day = Friday then
17
3346
by: Franc Zabkar | last post by:
My D-Link DSL-302G modem/router has a real-time clock whose settings are volatile. To avoid hand keying the date/time via the modem's JS interface, I wonder if there is a way to copy the JS code to the hard drive and modify it to automatically retrieve the PC's date/time. I could then add the hacked JS page to my browser's bookmarks. I've...
1
2054
by: Drum2001 | last post by:
I have a table that contains the following fields: ItemName // Name of Assignment AvgTime //Estimated number of mins to complete I have a form that has a combo box listing all assignments (Record Source: ItemName) This form also contains three textboxes and and
1
1655
by: John | last post by:
Hi How can I subtract 10 minutes from a date/time value? Thanks Regards
4
23626
by: Chris Shenton | last post by:
I set this up 3 days ago and have not seen any of the logs I've created this way being rotated. I expected them to rotate every midnight. I'm calling the code that uses this logger many times, each a separate run, if that matters. Am I doing something stupid? I can't find anything on google and don't see anything in the code that would...
5
2656
by: Mark Olbert | last post by:
I just noticed something weird about the calendar control in ASPNET2. If you assign a value to SelectedDate that has a time component (e.g., 3/1/2007 10:37 AM), and you have a custom style for the selected day, the selected day will not be rendered using the custom style. Instead, the control acts like >>no<< date has been selected. I came...
1
7396
by: electroon | last post by:
Hi frnds, I have written a code to get current time struct tm *locTime; time_t currentTime; time( &currentTime ); locTime = localtime(&currentTime ); Suppose now i get output time as 31-DEC-2007 00:00:00
25
4528
by: Brian | last post by:
I have a datetimepicker formated for just time, the user selects the time. I want to compare if that time is between midnight and 8 am dtmTime #11:59:59 PM# and dtmTime < #08:00:00 AM# this evaluates to true when the time is not greater than dtmTime #9:32:34 PM# Why is that? and How can I get this to work? Brian
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3875
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2353
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.