SQL为类型为" date"的列添加2小时

时间:2016-11-07 06:17:52

标签: sql oracle

我在Select语句中有一个包含日期的列,我想在此Select的每一行中添加2小时。

有什么建议吗?

3 个答案:

答案 0 :(得分:2)

enter image description here

CREATE TABLE testtime (my_date datetime);
  INSERT INTo testtime VALUES (GETDATE());

打印实际日期

  select * from testtime

这打印时间+ 2小时

  select DATEADD(HOUR, 2, my_date) from testtime

答案 1 :(得分:2)

MS Access更新查询:

UPDATE Table1 AS t2 INNER JOIN Table1 ON t2.ID = Table1.ID 
SET Table1.DeliveryDate = DateAdd("hh",2,[t2].[DeliveryDate]);

Sql Server更新查询:

SELECT DateAdd("h",2,Table1.DeliveryDate) AS NewDateTime
FROM Table1;

MS Access选择查询:

SELECT DateAdd("hh",2,Table1.DeliveryDate) AS NewDateTime
FROM Table1;

Sql Server选择查询:

SELECT (Table1.DeliveryDate + 2/24) AS NewDateTime
FROM Table1;

Oracle Select Query:

{{1}}

答案 2 :(得分:2)

我更喜欢使用interval

select deliverydate + interval '2' hour
from the_table;

以上是标准SQL,在Oracle中运行良好。

手册中的更多详细信息:https://docs.oracle.com/database/121/SQLRF/sql_elements003.htm#SQLRF00221