gpt4 book ai didi

sql-server - 从sql查询中的当前时间戳获取天数

转载 作者:行者123 更新时间:2023-12-04 06:01:37 25 4
gpt4 key购买 nike

我有一张 table

ID      Timestamp
1 2010-07-27 13:14:00.000
2 2010-08-13 13:14:00.000
3 2010-12-21 13:14:00.000

现在我需要使用当前的 getdate() 从 Timestamp 列中减去日期
并从中得到日子

希望我的问题很清楚,任何帮助都会很棒

谢谢
王子

最佳答案

您可以使用 DATEDIFF

SELECT DATEDIFF(day, Timestamp, getdate())
FROM YourTable

DATEDIFF

Returns the count (signed integer) of the specified datepart boundaries crossed between the specified startdate and enddate.



语法
DATEDIFF ( datepart , startdate , enddate )

关于sql-server - 从sql查询中的当前时间戳获取天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8847029/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com