简体   繁体   English

如何在获取日期中输入手动时间戳()

[英]how to enter manual time stamp in get date ()

how to enter manual time stamp in get date () ? 如何在获取日期()中输入手动时间戳?

select conver(varchar(10),getdate(),120)

returns 2010-06-07 返回2010-06-07

now i want to enter my own time stamp in this like 2010-06-07 10.00.00.000 现在我想以这种方式输入自己的时间戳2010-06-07 10.00.00.000

im using this in 我在用这个

select * from sample table where time_stamp ='2010-06-07 10.00.00.000' 从样本表中选择*,其中time_stamp ='2010-06-07 10.00.00.000'

since im trying to automate this query i need the current date but i need different time stamp can it be done . 由于即时通讯试图自动执行此查询,所以我需要当前日期,但我需要不同的时间戳才能完成。

You just want to append a time to your result? 您只想在结果上加上一个时间? Like this? 像这样?

select convert(varchar(10),getdate(),120) + ' 10.00.00.000'

or if you want to get it back to a DATETIME type: 或者如果您想将其恢复为DATETIME类型:

select convert(datetime,convert(varchar(10),getdate(),120) + ' 10:00')
--SQL Server 2008
DECLARE @MyTime time, @MyDate date

SELECT @MyDate = GETDATE(), @MyTime = '10:00:00'

SELECT CAST(@MyDate AS datetime) + @MyTime

--SQL Server 2005 and before
DECLARE @MyTime datetime, @MyDate datetime

SELECT
   @MyDate = DATEADD(day, 0, DATEDIFF(day, 0, GETDATE())),
   @MyTime = '19000101 10:00:00'

SELECT @MyDate + @MyTime

"zero" date = 01 Jan 1900 in SQL Server SQL Server中的“零”日期= 1900年1月1日

SELECT DATEADD(hh, 1, FLOOR(CAST(GETDATE() AS FLOAT)))

Once you have the floor of the date, you can add time to it. 确定日期的下限后,您可以为其添加时间。

DATEADD(datepart, number, date) DATEADD(日期部分,数字,日期)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM