首页 > 解决方案 > 如何获取今天午夜到昨天午夜的数据

问题描述

我正在寻找从今天午夜到昨天午夜的数据。如果今天的日期“2020-06-10 03:20:25”。我想在“2020-06-09 00:00:00”到“2020-06-10 00:00:00”之间创建

标签: sqlpostgresqldate-arithmetic

解决方案


假设createdate是一timestamp列:

where createdate >= date_trunc('day', current_timestamp) - interval '1 day'
  and createdate < date_trunc('day', current_timestamp) + interval '1 day';

推荐阅读