bindiya Posted December 31, 2010 Share Posted December 31, 2010 i have a mysql query nto find the time difference between current time and the time in the databse table filed. but i get error.the datatype used in table is time.the time difference should be displayed in hours my query is SELECT TIMEDIFF(curtime, date_posted) FROM page_view here date_posted is my field in the table. Quote Link to comment https://forums.phpfreaks.com/topic/223058-error-getting-while-finding-the-time-difference/ Share on other sites More sharing options...
joel24 Posted January 1, 2011 Share Posted January 1, 2011 what type of field is date_posted... datetime, unix timestamp, etc? In TIMEDIFF() you need both the times/dates to be of the same type... And do you just want the time difference, or the date difference, or both? date & time functions Quote Link to comment https://forums.phpfreaks.com/topic/223058-error-getting-while-finding-the-time-difference/#findComment-1153469 Share on other sites More sharing options...
bindiya Posted January 1, 2011 Author Share Posted January 1, 2011 the datatype for the field is datetime. i need the time difference Quote Link to comment https://forums.phpfreaks.com/topic/223058-error-getting-while-finding-the-time-difference/#findComment-1153483 Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2011 Share Posted January 1, 2011 When you get errors, it's usually helpful to post them with the code, but try this. SELECT TIMEDIFF( NOW( ) , `date_posted` ) FROM `page_view` Quote Link to comment https://forums.phpfreaks.com/topic/223058-error-getting-while-finding-the-time-difference/#findComment-1153485 Share on other sites More sharing options...
joel24 Posted January 1, 2011 Share Posted January 1, 2011 The two times/dates need to be of the same type. TIMEDIFF(curtime, date_posted) ... you have a time field and a datetime field. You need to do TIMEDIFF(curtime(), TIME(date_posted)) Quote Link to comment https://forums.phpfreaks.com/topic/223058-error-getting-while-finding-the-time-difference/#findComment-1153486 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.