求助SQL怎么可以让时间相减

crystal522 2011-04-28 06:09:51
Arrive_time Left_time
16:05:00 17:10:00
0:00:00 1:30:00
12:25:00 13:15:00
12:45:00 13:50:00

想运行SQL新建一个lefttime-arrivetime
SELECT Left_time-Arrive_time as time_period

但是好像时间不能直接这样减 改怎么处理啊

最好方法能简单一些 没有学得很深入
...全文
957 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
yusheng622 2011-04-30
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 claro 的回复:]

SQL code
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
[/Quote]
就这样啊!
晓风斜阳 2011-04-30
  • 打赏
  • 举报
回复
DATEDIFF ,SQLSERVER系统原生函数
CSDNsa 2011-04-28
  • 打赏
  • 举报
回复
举个简单的例子:

常用函数:

YY :年

M :月

D :日

N :分钟

S :秒

SELECT DATEDIFF(N,'2011-04-28 16:05:00','2011-04-28 17:10:00')

这个结果得到后面那个时间和前面那个时间相差的分钟:65

其他同理

cs_lb 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 lihaipeng1224 的回复:]
select datediff(second ,Arrive_time,Left_time) as arrive_left_time from TB

但是日期时间貌似也可以直接相减的吧?
[/Quote]
时间类型减时间类型得到的还是时间


SELECT DATEDIFF(second, Arrive_time, Left_time) AS arrive_left_time
FROM TB


yubofighting 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 fredrickhu 的回复:]
SQL code
datediff(ss,Arrive_time,Left_time)
[/Quote]

++
--小F-- 2011-04-28
  • 打赏
  • 举报
回复
datediff(ss,Arrive_time,Left_time)
lddlq0810 2011-04-28
  • 打赏
  • 举报
回复

-- 秒
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
wulg10 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 claro 的回复:]

SQL code
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
[/Quote]
lihaipeng1224 2011-04-28
  • 打赏
  • 举报
回复
select datediff(second ,Arrive_time,Left_time) as arrive_left_time from TB

但是日期时间貌似也可以直接相减的吧?
lantian_019 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 claro 的回复:]
SQL code
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
[/Quote]
正确!
claro 2011-04-28
  • 打赏
  • 举报
回复
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
claro 2011-04-28
  • 打赏
  • 举报
回复
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period
xqx_8888 2011-04-28
  • 打赏
  • 举报
回复
dateiff
crystal522 2011-04-28
  • 打赏
  • 举报
回复
错了。。。要精确到秒 - - 在国外 这大半夜的 不容易啊

我看了网上很多帖子 我用不进去啊 求助求助 多谢大神们
crystal522 2011-04-28
  • 打赏
  • 举报
回复
要精确到分!!!

求助
crystal522 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 claro 的回复:]
SQL code
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
[/Quote]

楼上很多办法我昨天晚上就试过了
但是无论我输入S还是SS run之后都会弹出来enter parameter value 然后我按OK 出来的就是表格标题是对的 然后下面的数据全是error
Tosp2012 2011-04-28
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 claro 的回复:]
SQL code
SELECT DATEDIFF (S,Arrive_time,Left_time) as time_period from table
[/Quote]

正解+1
haosa 2011-04-28
  • 打赏
  • 举报
回复
DATEDIFF()函数

34,838

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧