Question : MySQL query by hour difference

Given three separate fields

DateField date (standard MySQL date format)
TimeField time (standard MySQL time format)
Hours int(3) (integer format)

I need a MySQL query that will select all records where the date/time from DateField/TimeField is within Hours of current datetime.  It's a problem because the date and time fields are separate, but I have no choice about that now.  Can someone suggest a good way to formulate this query?

Answer : MySQL query by hour difference

hi, try this
1:
2:
3:
SELECT *
FROM tablename
WHERE ABS(DATEDIFF(DateField,curdate())*24+ TIMEDIFF(TimeField,curtime()))<=Hours
Open in New Window Select All
Random Solutions  
 
programming4us programming4us