PDA

View Full Version : Another MySQL question


hairsoup
2nd January 2006, 13:38
What I am trying to do, I have two fields in a table, both datetime type, i want to find out the average time between the two in hours.

something like this:

select avg(magic_date_function(date1, date2)) from table

but with a less fictional function for working out the number of hours between two dates. looked in manual but cant find anything

Richard Conyard
2nd January 2006, 13:39
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

Here you go - it's the datediff function

I am not sure since I stopped using mySQL years ago, but you might need to select the results into a temporary table before running the avg function.

hairsoup
2nd January 2006, 14:22
thanks, tried it, and i can only get datediff to work with avg() get an error without?

Coding Monkey
2nd January 2006, 14:27
If you show us the code we could help more

hairsoup
2nd January 2006, 15:05
its ok solved it now, thanks.

DuaneJackson
2nd January 2006, 15:07
Can you post the solution? It drives me mad when I am searching on a problem in Google then find a forum where someone solved it but didn't post how :)