zoukankan      html  css  js  c++  java
  • SQL计算两个时间段相隔时间

    SQL语句:

    select cast(floor(datediff(minute,时间1,时间2) / 1440) as varchar)+'天'+

           cast(floor((datediff(minute,时间1,时间2) % 1440)/60) as varchar)+'小时'+

           cast(((datediff(minute,时间1,时间2))-

               (floor(datediff(minute,时间1,时间2) / 1440) *1440)-

               (floor((datediff(minute,时间1,时间2) % 1440)/60)*60)) as varchar)+'分'

     from 表名

    返回:xx天xx小时xx分

    ----------------------------------------------------------------------------------------------------------------

    实例:

    select oc.ID,oc.CarNumber,oc.PrintTime1,oc.PrintTime2, (

     cast(floor(datediff(minute,oc.PrintTime1,oc.PrintTime2) / 1440) as varchar)+'天'+

           cast(floor((datediff(minute,oc.PrintTime1,oc.PrintTime2) % 1440)/60) as varchar)+'小时'+

           cast(((datediff(minute,oc.PrintTime1,oc.PrintTime2))-

               (floor(datediff(minute,oc.PrintTime1,oc.PrintTime2) / 1440) *1440)-

               (floor((datediff(minute,oc.PrintTime1,oc.PrintTime2) % 1440)/60)*60)) as varchar)+'分') interval
     from t_ordercar oc
    left join t_order o on oc.OrderID = o.ID
    where o.SupplierName='金冠电厂2'  and  datediff(d,o.AddTime,'2017-12-19') =0

    返回结果:

  • 相关阅读:
    449. Serialize and Deserialize BST
    3. Longest Substring Without Repeating Characters
    2. Add Two Numbers
    240. Search a 2D Matrix II
    5. Longest Palindromic Substring
    数位DP专题(开坑。
    POJ 2356
    HDU 4055
    HDU 4054
    HDU 1559
  • 原文地址:https://www.cnblogs.com/weimingxin/p/8109215.html
Copyright © 2011-2022 走看看