1

So this is what I'm trying to do I just want to know if there's a way to link the date input command to my SQL query so that anyone that runs the code can enter a date and get the info for only that specific date. (super-duper noob here)

date = input("DATE:YYYY-MM-DD")
query = '''
SELECT timestamp , something , someotherthing 
FROM database
WHERE timestamp = date
'''
pd.read_sql_query(query,con)

2 Answers 2

1

To get the date for the input to commend you can format your string

date = input("DATE:YYYY-MM-DD")
query = '''
SELECT timestamp , something , someotherthing 
FROM database
WHERE timestamp = {date}
'''
pd.read_sql_query(query.format(date=date),con)

or without the date param

date = input("DATE:YYYY-MM-DD")
query = '''
SELECT timestamp , something , someotherthing 
FROM database
WHERE timestamp = {}
'''
pd.read_sql_query(query.format(date),con)
Sign up to request clarification or add additional context in comments.

Comments

0

Concatenate the strings.

date = input("DATE:YYYY-MM-DD")
query = "SELECT timestamp , something , someotherthing \
FROM database \
WHERE timestamp = " + str(date)

pd.read_sql_query(query,con)

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.