I have a list of TimeObjects.

I want to subtract 5h from each element and if TimeObject < 5h then give a negative hour.

My goal is to count the amount of time that I’ve worked last month. To doing that I have a list of the amount time worked each day so that {{13/9,7:00}...} I make with that a list of DateValue to that I have to subtract 5h to each element to know only the extra time that i’ve worked.

How could I do this?


  • $\begingroup$ Can't you just compute times - TimeObject[{5, 0, 0}]? That's what the documentation seems to imply. Count[..., _?Negative] or Count[..., _?Positive] etc. to count a particular type of result. $\endgroup$ – Michael E2 Jan 30 '16 at 13:15
  • $\begingroup$ I have corrected my answer according to the format you provided. Please accept it by selecting the tick mark if it answered your question. Thanks! $\endgroup$ – Pavlo Fesenko Feb 2 '16 at 13:02

If your working hours are stored in the list time according to the format you provided, then your total overtime can be calculated like this

time = {{"13/9", "7:00"}, {"14/9", "3:30"}};
overtime = TimeObject@DateList@{#[[2]], {"Hour", ":", "Minute"}} - 
 TimeObject@DateList@{"5:00", {"Hour", ":", "Minute"}} & /@ time;
| improve this answer | |
  • 1
    $\begingroup$ Why does ‘TimeObject’ subtraction shows in minutes? $\endgroup$ – kafkarudo Jan 30 '16 at 15:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.