0

I would like to import rows from mySQL database into Python. I would like to take out rows between two dates that have the same timstamp. I have managed to import between two dates with this line:

"SELECT * FROM table WHERE timestamp >= %s AND timestamp <=%s", (2020-03-07, 2020-03-10)

But I dont know how to spesific only rows where timestamp is for example 10:00:00. See picture for the database setup.

Database Database

1
  • how to spesific only rows where timestamp is for example 10:00:00 CAST this field to TIME datatype or format it to '%H:%i:%s' (i.e. remove date part), then compare with proper time literal. Commented Mar 10, 2020 at 12:45

1 Answer 1

2

You need something like

"""
SELECT * 
FROM table 
WHERE timestamp >= %s 
  AND timestamp <=%s 
  AND DATE_FORMAT(timestamp, '%H:%i:%s' = %s)
""", ("2020-03-07", "2020-03-10", "10:00:00")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.