I am converting my PHP/mySQL code to PDO but I am having some difficulties. Below I have added the exact code I am using with example for better understanding. My goal is to show the name from the DB that their time compared with the one on input differ by 2 hours.
this is the code
SELECT * FROM events WHERE TIMESTAMPDIFF( HOUR , TIME, :input ) < 2
this is my database
name date
3D Brave 2012-07-21 17:00:00
Bol Bachchan 2012-07-21 18:00:00
A Royal Affair 2012-07-21 19:00:00
Not Suitable For Children 2012-07-21 23:00:00
If the $input is 2012-07-20 18:00 or 2012-07-20 20:00 then I get all the results as below, but it should show only those that have a difference 2 hours
3D Brave
Bol Bachchan
A Royal Affair
Not Suitable For Children
Well, you’re querying the difference from the column
TIME, but in the table schema, it’s calleddate.Corrected query:
What I did:
dateABS()function (so it now looks both forwards and backwards).The result of that query.