如何在数据库H2中更改没有时间的字段日期时间

How to change the field datetime without time in database H2

我有一个 table:

CREATE TABLE `operation` (
  `id` bigint(20) NOT NULL,
  `start_time` datetime DEFAULT NULL,
  `finish_time` datetime NOT NULL
);

为此 table,您需要将 finish_time 的值插入到 start_time。通过无时间转换字段。

例如:“2018-02-02 10:10:10”=>“2018-02-02 00:00:00”

我知道如何为 MySQL 做这个:

update operation
set start_time = DATE_FORMAT(finish_time,'%y-%m-%d')
where start_time is null;

但是H2中没有这个函数DATE_FORMAT

如何对数据库 H2 执行此查询?

您可以尝试使用 FORMATDATETIME()

update operation
set start_time = FORMATDATETIME((finish_time, '%y-%m-%d')
where start_time is null;

您可以使用CAST()去除时间信息。例如:

update operation
set start_time = cast(finish_time as date)
where start_time is null;