Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8284057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:57:31+00:00 2026-06-08T10:57:31+00:00

I am converting my PHP/mySQL code to PDO but I am having some difficulties.

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:57:33+00:00Added an answer on June 8, 2026 at 10:57 am

    Well, you’re querying the difference from the column TIME, but in the table schema, it’s called date.

    Corrected query:

    SELECT *
      FROM events 
      WHERE ABS(TIMESTAMPDIFF( HOUR , `date`, "2012-07-21 18:00:00")) < 2;
    

    What I did:

    • Changed column name to date
    • Added ABS() function (so it now looks both forwards and backwards).

    The result of that query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MySQL singleton class written in PHP. Its code is listed below:
I am facing some problems converting the PHP SQL insertion code below to ASP,
I have currently switched to using PDO but am having trouble in handling the
[Updated below] I am having a problem connecting to a MySQL database using a
I am trying to connect to MySQL DB using php script. But I don't
I have this code: <?php // Make a MySQL Connection $dbhost = 'xxx'; $dbuser
I am converting some of my code from the older mysql extension to the
I have been trying to display image from database using php but i am
I'm converting a PHP script as DB has been switched from MySQL to PostgreSQL.
What is the php script for converting a mysql table to text file? I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.