user1745447
user1745447

Reputation: 37

DateDiff function in MYSQL 5.1. Need Hours+Mins

MYSQL 5.1

I need to create a query that gives my result table three columns, match_date, match_start and match_duration

I need the match_duration column which takes match_start and match_end and displays how long each game has been on for in 00:00 hours format. So for example if it were 5hrs:30 mins it would be displayed 5:30 hours.

This is what I have so far and not sure where I'm going wrong:

SELECT match_date, match_start, DateDiff(hhmm, match_start, match_end) AS Duration
FROM MatchInfo;

Thanks

Upvotes: 0

Views: 3425

Answers (1)

Yogendra Singh
Yogendra Singh

Reputation: 34367

Try below:

  TIME_FORMAT(TIMEDIFF(match_end, match_start), '%H:%i')

i.e.

   SELECT match_date, match_start, 
          TIME_FORMAT(TIMEDIFF(match_end, match_start), '%H:%i') AS DURATION
   FROM MatchInfo;

Upvotes: 4

Related Questions