1

I am working on a spring api where I am using postgres and saving a field of type timestamp with field name as created_date. Now I want to check whether this field is between two different timestamps.

Right now I am using this:

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

Is there a way I can use BETWEEN here for this operation?

rudeTool
  • 462
  • 1
  • 3
  • 16

1 Answers1

2

You can do it like this:

SELECT *
FROM  your_table
WHERE created_date BETWEEN '2020-06-22 19:10:25-07'
AND '2020-06-23 19:10:25-07'

If you want to do it using JDBC, check this answer and this answer.

Arvind Kumar Avinash
  • 62,771
  • 5
  • 54
  • 92
  • thanks but will it work if the second param in BETWEEN in empty string,will it return the record with condition matching with first param? first param=first timestamp, second param=second timestamp – rudeTool Jun 27 '21 at 06:38
  • `BETWEEN` requires two values. If you want to work with only the first value, you can use `SELECT * FROM your_table WHERE created_date >= '2020-06-22 19:10:25-07'`. – Arvind Kumar Avinash Jun 27 '21 at 06:46