Message Boards Message Boards

0
|
4286 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Date/Time calculation without nights?

Posted 7 years ago

Hi! Have a quick question about Date/Time calculations. Let's say I have two dates+times. Then I can use the following function to find the hours between the two date/times:

a1 ={2015, 8, 4, 20, 34, 0.`}
a2={2015, 8, 6, 9, 39, 0.`}
DateDifference[a1,a2,"Hour"]

The First day is 4-8-2015 (d-m-y) and the time is 8.34 pm.

The Second day is 6-8-2015 and the time is 9.39am

The gross time difference is 37.0833 hours.

What I want to find is a function that gives the hours difference excluding any times between 10pm and 9am. So we need the time difference between 8.34 pm and 10pm for first day [1h 26m], then the whole of second day (9am to 10pm = [13 hours]), plus on the third day the time difference between 9am and 9.39 am [39 minutes]. Thus the function should output 1h26m + 13h + 39m.

This function should work for any arbitrary dates/times. I wonder if someone is able to help me come up with such a function?.

Cheers, Priyan.

POSTED BY: Priyan Fernando
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract