'Query returns function plus the value inside instead of just the value
I'm running a select query and for fetching date and time data from the database but for some reason the returned value is datetime.date(2021, 11, 18)
and datetime.time(19, 19, 29)
instead of just the time and date
The current_date and current_time are instantiated as shown below:
time = datetime.datetime.now()
CURRENT_TIME = time.strftime('%H:%M:%S')
CURRENT_DATE = datetime.date.today()
The script to add the date and time data is this:
update_script = "UPDATE holding SET MEETINGDATE = '{}', MEETINGTIME = '{}'".format(CURRENT_DATE,CURRENT_TIME)
Here's the select query to fetch the data:
retrieve_script = "SELECT STUDENTID,STUDENTNAME,STUDENTEMAIL,MEETINGDATE,MEETINGTIME FROM meeting1"
Any clue why this is so, and how can I fix it?
Solution 1:[1]
I opted use SQLAlchemy ORM to create my table as a model then generate it using db.create_all()
This allowed me to access individual records without the quotes for example: Before I was getting 'John Doe' returned but now I get John Doe without the quotes.
More information can be found on the flask official documentation here https://flask-user.readthedocs.io/en/latest/data_models.html
I hope this comes in handy for someone.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dancun Gerald |