如何在 SQL Server 中将小时添加到当前日期? [英] How to add hours to current date in SQL Server?

查看:39
本文介绍了如何在 SQL Server 中将小时添加到当前日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将小时添加到当前时间,如

I am trying to add hours to current time like

-- NOT A VALID STATEMENT
-- SELECT GetDate(DATEADD (Day, 5, GETDATE()))

如何在 SQL Server 中提前数小时?

How can I get hours ahead time in SQL Server?

推荐答案

DATEADD (datepart , number , date)

declare @num_hours int; 
    set @num_hours = 5; 

select dateadd(HOUR, @num_hours, getdate()) as time_added, 
       getdate() as curr_date  

这篇关于如何在 SQL Server 中将小时添加到当前日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆