gpt4 book ai didi

sql - datediff 没有返回我所期待的

转载 作者:行者123 更新时间:2023-12-04 02:53:19 26 4
gpt4 key购买 nike

有人知道为什么以下返回 8 吗?我预计 8 小时 30 分钟,还是 8.5?

declare @start_day datetime;
declare @end_day datetime;
declare @start_time datetime;
declare @end_time datetime;

set @start_day = '2014-06-18';
set @end_day = '2014-06-18';
set @start_time = '09:00';
set @end_time = '17:30';

print datediff(hour,@start_day + @start_time, @end_day + @end_time);

最佳答案

试试这个,将分钟的 DATEDIFF 转换为 float ,然后除以 60 得到小时数。

declare @start_day datetime;
declare @end_day datetime;
declare @start_time datetime;
declare @end_time datetime;

set dateformat ymd

set @start_day = '2014-06-18';
set @end_day = '2014-06-18';
set @start_time = '09:00';
set @end_time = '17:30';

print cast(datediff(minute,@start_day + @start_time, @end_day + @end_time) as float) / 60;

关于sql - datediff 没有返回我所期待的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17165008/

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