acidglitter Posted February 24, 2008 Share Posted February 24, 2008 i have a column thats a datetime type. what mysql query would show how many days, hours, minutes from the saved date until now? like date in table: 2008-02-25 12:00:00 query result (something like this..): 0000-00-01 01:00:00 or.. what query would get this result?: 25 hours (until date saved in table) Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/ Share on other sites More sharing options...
paul2463 Posted February 24, 2008 Share Posted February 24, 2008 have a look here in the <a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timediff">MYsql Manual </a>for the function <a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timediff"> time_diff() </a> Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475136 Share on other sites More sharing options...
acidglitter Posted February 24, 2008 Author Share Posted February 24, 2008 but what do i put in the timediff()? something like this doesn't want to work.. TIMEDIFF(DATETIME(table_column), CURTIME()) Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475144 Share on other sites More sharing options...
paul2463 Posted February 24, 2008 Share Posted February 24, 2008 $query = "SELECT TIMEDIFF(date_column, CURTIME()) AS diff FROM date_table"; Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475151 Share on other sites More sharing options...
acidglitter Posted February 24, 2008 Author Share Posted February 24, 2008 thanks for your help so far. i tried that though and nothing showed up.. Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475153 Share on other sites More sharing options...
paul2463 Posted February 24, 2008 Share Posted February 24, 2008 $query = "SELECT TIMEDIFF(date_column,NOW()) AS diff FROM date_table"; //just looked and CURTIME() onloy returns the time NOW() returns the date time Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475156 Share on other sites More sharing options...
acidglitter Posted February 24, 2008 Author Share Posted February 24, 2008 so i have this right now, and its *almost* perfect.. HOUR(TIMEDIFF(date_column,NOW())) the problem is, i'm also trying to use that here like.. WHERE HOUR(TIMEDIFF(date_column,NOW())) > 0 and you would think that old rows with a date before today would have negative numbers, but they don't.. so when i put that for where to select it shows ALL of the rows... what am i doing wrong? Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475173 Share on other sites More sharing options...
acidglitter Posted February 24, 2008 Author Share Posted February 24, 2008 so i changed the where clause to be TIMEDIFF(date_column, NOW()) > -1 and it seems to be working perfectly right now. does anyone see any problems with doing it this way? Quote Link to comment https://forums.phpfreaks.com/topic/92737-solved-datetime-difference/#findComment-475201 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.