I have this query that by default, gets all the data within the past 60 minutes (from the current time). However, the user also has the ability to select a time (thus the parameter newTime). I want to get all the past data within the past hour of that selected time.
@app.route('/_ajax', methods=['GET', 'POST'])
def userCount():
try:
newTime = request.form['time']
except:
newTime = datetime.now()
cur.execute("""SELECT count(DISTINCT(username)) from user_table WHERE tstampz >
(%s::date - INTERVAL '60 mins')""", (newTime,))
count=cur.fetchone()[0]
This works perfectly for the current time, yet when I change the time selection, it displays an aggregate of data from 60 minutes ago all the way back to the selected date.
What I want: If I select August 1st at 2 PM, I want all the data from August 1st 1 PM - 2 PM.
What I'm getting: All the data from August 1st at 2 PM to 60 minutes ago.
How can I make query compatible with the intervals I'm looking for?