知道一个时间戳,如何使用SQL提取天、小时、分钟
取时间戳的天数:fd_cost_time/(1000 * 60 * 60 * 24)
取时间戳的小时数:(fd_cost_time% (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)
取时间戳的分钟数:(fd_cost_time % (1000 * 60 * 60)) / (1000 * 60)
取时间戳的秒数:(fd_cost_time % (1000 * 60)) / (1000)
备注:
1.fd_cost_time为时间戳或时间戳所在字段;
2.如果要将计算结果转为整型,可使用CONVERT(INT, YourColumn) 或CAST(YourColumn AS INT);YourColumn
是包含要提取整数值的字段名
3.使用convert()或cast()将天、小时、分钟、秒转为整型
取时间戳的天数转为整型:convert(int,fd_cost_time/(1000 * 60 * 60 * 24) ) 天数
取时间戳的小时数转为整型:convert(int,(fd_cost_time% (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)) 小时数
取时间戳的分钟数转为整型:cast((fd_cost_time % (1000 * 60 * 60)) / (1000 * 60) as int) 分钟数
取时间戳的秒数转为整型:cast((fd_cost_time % (1000 * 60)) / (1000) as int) 秒数