Mahesh
Mahesh

Reputation: 1333

Convert date string to timestamp with timezone in python

I have a date string 2020-10-14, 14:13:23, I want to convert this to timestamp with timezone format in python so that I can delete the rows with this particular timestamp in my postgresql table

enter image description here

Please suggest how to proceed?

Upvotes: 0

Views: 1294

Answers (1)

GMB
GMB

Reputation: 222582

Do you want to cast?

select '2020-10-14, 14:13:23'::timestamp with time zone
| timestamptz            |
| :--------------------- |
| 2020-10-14 14:13:23+01 |

If you want to filter on timestamps that belong to the same second as this literal value:

select *
from mytable
where execution_date >= '2020-10-14, 14:13:23'::timestamp with time zone
  and execution_date <  '2020-10-14, 14:13:23'::timestamp with time zone + interval '1 second'

Upvotes: 1

Related Questions