I might be confusing it with mysql “TIMEDIFF”.
In that case, how do i calculate time differenes using PHP? If I want to show the difference in hours between 2013-07-26 10:00:00 and 2013-07-26 10:30:00, how do I do it?
Thanks
I know where you’re coming from, probably 90% of the questions that get asked here on the forum could be answered by searching google, but we can’t just answer ‘google it’ all the time or it’d be a pretty empty forum.
The other responders showed you how to calculate a time difference using php functions. Which is perfectly understandable give that this is a php forum. However, if you want your database to do the calculations then just make a select statement and execute it.
By doing this you can calc the difference between two datetimes columns without having to query the column values and then convert to php’s format. Of course these sort of functions tend to be database specific so it can limit flexibility.
He didn’t say much
My problem is solved whereby another post where fertburner suggested to change column type to “TIME”. Only then the code you posted worked.
It turned out to be a MySql problem but I didn’t recognize it at the beginning. I’ve been doing MySql for 2/3 days only. Before that I was working with SQLServer where I didn’t have to distinguish between t_sql and SQL. Now I’ll have know to where HTML extends, PHP, MySQL not mentioning CSS Javascript and much more… Knowing which forum to ask a question is a skill for itself.
It’s also slower to do statements like this in mysql, because mysql will not use it’s query cache when you’re using time and date functions in select statements.
There are plenty of date related functions that will have this impact though:
CURDATE()
CURRENT_DATE()
CURRENT_TIME()
CURRENT_TIMESTAMP()
CURTIME()
NOW()
UNIX_TIMESTAMP() with no parameters