I am trying to total up all the timesdate seperately from a few different columns in my database, however when the total for each surpasses 24 hours – I’m only getting 00:00 printed instead of the actual total.
I understand that the PHP date “H” variable only cover 00 – 23, so am unsure the best way to go about doing this. Any help would be much appreciated.
My SQL select code is:
SEC_TO_TIME( SUM( TIME_TO_SEC(lunch) ) ) AS lunch,
SEC_TO_TIME( SUM( TIME_TO_SEC(overtime) ) ) AS overtime,
SEC_TO_TIME( SUM( TIME_TO_SEC(day_paid) ) ) AS day_paid,
SEC_TO_TIME( SUM( TIME_TO_SEC(lunch) ) ) AS lunch,
SEC_TO_TIME( SUM( TIME_TO_SEC(holiday) ) ) AS holiday,
SEC_TO_TIME( SUM( TIME_TO_SEC(absence) ) ) AS absence
My view code as an example for “lunch” is:
echo date('H:i', strtotime($day_breakdown->day_paid);
The MySQL code you’ve written is fine, but the view code won’t work as it’s designed to work with dates/times and not with relative periods of time.
You should derive the hours/minutes by dividing the seconds out like this: