首页 > 解决方案 > 如何在postgres中比较时间戳数据类型和字符串?

问题描述

我将日期和时间作为时间戳格式存储在 postgres 中,如下所示:

created_time timestamp without time zone DEFAULT now(),

现在我想搜索具有created_timebetweendate_beforedate_after字段的行。这两个字段都是查询字符串。

我怎样才能用这个过滤数据?

标签: javaspringpostgresqlspring-boottimestamp

解决方案


在 Postgres 中,您可以简单地将时间戳与字符串进行比较:

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

记住不要使用带时间戳的 between


推荐阅读