Ray Zuchowski
Ray Zuchowski

Reputation: 383

Time Data Format Non Accepting On PostgreSQL

I have a script that goes into my outlook calendar to change a date on a event that is already posted (Django Project). Basically what happens is it does a query on the date you enter and searches for the name of the event. If it exists, it will delete the old event and post new. My current code im posting works on my dev server that is a SQL-Lite backend, my production server is on Heroku with PostgreSQL. It fails on my production. Here is my code.

           print('Authenticated W/ O365')        
           # Checkes if event exists in K8 Calendar 
           calendar = schedule.get_calendar(calendar_name ="K-8")
           calendar.name = 'K-8'
           print('Checking if Event Exits in K8 Calendar')
           print("Event Name:", obj.event_name)
           print("Event Start:", obj.start_date)
           print("Event End:", obj.end_date)   
           q = calendar.new_query('start').equals(datetime.strptime(str(obj.start_date) ,'%Y-%m-%d %H:%M:%S%z'))  <-- These are the lines that fail
           q.chain('and').on_attribute('end').equals(datetime.strptime(str(obj.end_date) ,'%Y-%m-%d %H:%M:%S%z')) <-- These are the lines that fail
           k8 = calendar.get_events(query=q, include_recurring = True) 

Traceback

ValueError at /eventscalendar/event_request_non_approval_view/49
time data '2020-10-31 14:00:18-04:00' does not match format '%Y-%m-%d %H:%M:%S%z'

Upvotes: 0

Views: 56

Answers (1)

Pavlo Golub
Pavlo Golub

Reputation: 399

try to use to_timestamp function to convert your custom format to PostgreSQL, e.g.

SELECT to_timestamp('2020-11-01 19:16:59:835', 'YYYY-MM-DD HH24:MI:SS:MS')

Details: https://www.postgresql.org/docs/13/functions-formatting.html

Upvotes: 1

Related Questions