社区电脑网络 → 浏览:帖子主题
* 帖子主题:SqlServer 获取时间差值,保留小数位
pojin (ID: 1)
头衔:论坛坛主
等级:究级天王[荣誉]
积分:1301
发帖:99
来自:保密
注册:2022-08-28 23:20:57
造访:2025-03-23 21:18:24
[ 第 1 楼 ] 回复
SELECT
DATEDIFF(month,'2021-05-16 18:00:00',getdate())*1.0/12 as '年差值' ,
cast(DATEDIFF(month,'2021-04-16 18:00:00',getdate())*1.0/12 as decimal(18,1)) as '年差值-保留小数位',
DATEDIFF(Hour,'2022-05-16 18:00:00',getdate())*1.0/24 as '天差值' ,
cast(DATEDIFF(Hour,'2022-04-16 18:00:00',getdate())*1.0/24 as decimal(18,1)) as '天差值-保留小数位',
DATEDIFF(MINUTE,'2022-05-16 18:00:00',getdate())*1.0/60 as '小时差值' ,
cast(DATEDIFF(MINUTE,'2022-05-16 18:00:00',getdate())*1.0/60 as decimal(18,1)) as '小时差值-保留小数位'
2023-02-10 15:22:01 IP:已设置保密
pojin (ID: 1)
头衔:论坛坛主
等级:究级天王[荣誉]
积分:1301
发帖:99
来自:保密
注册:2022-08-28 23:20:57
造访:2025-03-23 21:18:24
[ 第 2 楼 ] 回复
cast(datediff(m, birthday, getdate())*1.0/12 as decimal(3,0)) as age
2023-02-10 16:48:04 IP:已设置保密
分页: 1, 共 1 页
快速回复主题
账号/密码
用户: 没有注册?密码:
评论内容