Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare timestamp data type with string in postgres?

I have date and time stored in postgres as timestamp format in postgres like this:

created_time timestamp without time zone DEFAULT now(),

now I want to search for rows that have created_time between date_before and date_after fields. both these fields are query strings.

How can i filter data with this?

like image 722
rudeTool Avatar asked Jul 18 '26 00:07

rudeTool


1 Answers

In Postgres, you can simply compare the timestamp with the strings:

select *
from your_table
where created_time >= '2020-06-22 19:10:25-07'
and created_time < '2020-06-23 19:10:25-07'

Remember not to use between with time stamps

like image 151
TheWildHealer Avatar answered Jul 19 '26 16:07

TheWildHealer