我使用 Postgresql-14,我有一个名为“start_datetime”的时间戳字段,如下所示:
select start_datetime from table1
2021-08-01 07:00:00.000 +0700
2021-08-01 07:00:00.000 +0700
2021-08-02 07:00:00.000 +0700
2021-08-03 07:00:00.000 +0700
2021-08-04 07:00:00.000 +0700
2021-08-04 07:00:00.000 +0700
如何用C#代码查询timestamptz字段的日期,我希望查询日期'2021-08-02'和'2021-08-03'
我用:
我已经尝试过:
select
t.start_datetime
from
table1 t
where
to_char(t.start_datetime at time zone 'UTC','YYYY-MM-DD') >=
'2023-08-02'
and to_char(c.start_datetime at time zone 'UTC','YYYY-MM-DD') <= '2023-08-03'
但是没找到
考虑使用
date_trunc,而不是使用
to_char
:
SELECT DATE_TRUNC('day', my_timestamp_column AT TIME ZONE 'UTC') AS utc_date
FROM table1
WHERE DATE_TRUNC('day', my_timestamp_column AT TIME ZONE 'UTC') BETWEEN '2021-08-02' AND '2021-08-03'