1. Use SUM mysql statement for hours and minutes fields.
2. Change minutes to hours (/60) and keep the remainder as minutes (%60).
3. Collate time elements and labels for output.
Simple.
However, placing time as integer (seconds) in your DB would be easier - you should do this.
diafol
Rhod Gilbert Fan (ardav)
7,765 posts since Oct 2006
Reputation Points: 1,168
Solved Threads: 1,075
Oh hell, julzk, you didn't even format the date to unix. It's in European(?) format:
dd-mm-yyyy.
For a pure mysql solution:
SELECT FLOOR(SUM(UNIX_TIMESTAMP(CONCAT(STR_TO_DATE(<strong>end_date</strong>,'%d-%m-%Y'), ' ',<strong>end_time</strong>)) - UNIX_TIMESTAMP(CONCAT(STR_TO_DATE(<strong>start_date</strong>,'%d-%m-%Y'), ' ',s<strong>tart_time</strong>)))/3600) AS hrs, FORMAT(SUM(UNIX_TIMESTAMP(CONCAT(STR_TO_DATE(<strong>end_date</strong>,'%d-%m-%Y'), ' ',<strong>end_time</strong>)) - UNIX_TIMESTAMP(CONCAT(STR_TO_DATE(<strong>start_date</strong>,'%d-%m-%Y'), ' ',<strong>start_time</strong>)))/60%60,0) AS mins FROM <strong>datecalc</strong>
Change bold fields/table to your own.
This will give 2 'total' columns:
hrs
mins
If you had proper 'integer' unix timestamps, all this nastiness could be avoided - even if you were using php for the calculation part.
diafol
Rhod Gilbert Fan (ardav)
7,765 posts since Oct 2006
Reputation Points: 1,168
Solved Threads: 1,075
diafol
Rhod Gilbert Fan (ardav)
7,765 posts since Oct 2006
Reputation Points: 1,168
Solved Threads: 1,075