0

I have to parse a time and subtract with another time but it returns error when time is more than 23hours.

I have two variables $countWorkHours = 42:00:00 and $countStayDinner->lunch = 5 .

I'm using carbon and I'm doing this:

Carbon\Carbon::parse($countWorkHours)->subHours($countStayDinner->lunch)->format('H:i:s')

but returns me this error: DateTime::__construct(): Failed to parse time string (42:00:00) at position 0 (4)

It just work if first date is less than 24 hours. What is the problem? How can I solve that?

Thank you

user3242861
  • 1,839
  • 12
  • 48
  • 93
  • 1
    Duplicates should send you in the right direction - you're going to have to do your own math on the hours/minutes/seconds here. `42:00:00` isn't a valid date/time string as there's no 42 o'clock in our times. – ceejayoz Jan 21 '19 at 15:52
  • I think CarbonInterval/DateInterval might be what you need. The tricky part would be to convert your time string to a time period. – aynber Jan 21 '19 at 15:56

0 Answers0