首页 > 解决方案 > 如何将时间戳转换为日期

问题描述

在一个视图中,我正在投射一个没有时区的时间戳。

在我看来,这些中的任何一个都应该起作用:

Cast("Orders"."OrderDate" as Date),
Date("Orders"."OrderDate"),
"Orders"."OrderDate"::Date,

但他们都给出了错误

cannot change data type of view column "OrderDate" from timestamp without time zone to date

Postgres 11
pgAdmin 4.9

标签: postgresqlcastingtimestamp

解决方案


select date_trunc('day', now());
| 日期截断 |
| :--------------------- |
| 2019-08-31 00:00:00+01 |
select date_trunc('day', now())::date;
| 日期截断 |
| :--------- |
| 2019-08-31 |

db<>在这里摆弄


推荐阅读