I'm calling a database, and returning a datetime.datetime object as the 3rd item in a tuple.
The SQL statement is: SELECT name,name_text,time_received FROM {}.{} WHERE DATE(time_received)=CURRENT_DATE LIMIT 1
If I do print(mytuple[2]) it returns something like: 2017-05-31 17:21:19+00:00 but always with that "+00:00" at the end for every value. How do I remove that trailing "+00:00" from the datetime.datetime object?
I've tried different string-stripping methods like print(mytuple[2][:-6]) but it gives me an error saying that datetime.datetime object is not subscriptable. Thanks for any help!
Docs:
to_char(timestamp, 'YYYY-MM-DD HH24:MM:SS') would be one way.
For your specific case:
SELECT name,name_text,to_char(time_Received, 'YYYY-MM-DD HH24:MM:SS')
Time received (mytuple[2]) would then be formatted as character data instead of time.
So if your program is handling it as a date, we'd have to convert it back to a date datatype
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With