# 数据库中的时间差函数TimeDiff

Function TimeDiff(sBegin, sEnd)
Dim iHourB, iMinuteB, iSecondB, iMiniSecondB
Dim iHourE, iMinuteE, iSecondE, iMiniSecondE
Dim dTimeB, dTimeE, dTimeDiff
Dim iHour, iMinute, iSecond, iMiniSecond

iHourB = clng(Left(sBegin, 2))
iMinuteB = clng(Mid(sBegin, 4, 2))
iSecondB = clng(Mid(sBegin, 7, 2))
iMiniSecondB = clng(Mid(sBegin, 10, 4))

iHourE = clng(Left(sEnd, 2))
iMinuteE = clng(Mid(sEnd, 4, 2))
iSecondE = clng(Mid(sEnd, 7, 2))
iMiniSecondE = clng(Mid(sEnd, 10, 4))

dTimeB = iHourB * 3600 + iMinuteB * 60 + iSecondB + iMiniSecondB / 1000
dTimeE = iHourE * 3600 + iMinuteE * 60 + iSecondE + iMiniSecondE / 1000
dTimeDiff = dTimeE - dTimeB

iHour = Int(dTimeDiff / 3600)
dTimeDiff = dTimeDiff - iHour * 3600
iMinute = Int(dTimeDiff / 60)
dTimeDiff = dTimeDiff - iMinute * 60
iSecond = Int(dTimeDiff)
dTimeDiff = dTimeDiff - Int(dTimeDiff)
iMiniSecond = dTimeDiff

TimeDiff = iHour & "小时" & iMinute & "分钟" & iSecond & FormatNumber(iMiniSecond, 3) & "秒"
End Function

#### SQL timediff 引发的血案

2016-09-07 08:53:00

#### hive中的udf时间函数用法

2012-03-28 09:41:41

2016-05-31 01:01:11

#### MySQL 时间函数加减计算

2015-09-15 17:50:38

#### MySQL的TIMEDIFF和DATEDIFF

2015-10-06 09:18:14

#### sql中两个时间类型相减得到的值

2012-12-29 18:11:19

#### mysql timediff函数极限值

2016-04-12 15:22:20

#### MySQL时间函数TIMEDIFF溢出

2014-07-31 17:12:02

#### MySQL DATEDIFF TIMEDIFF

2013-09-05 17:28:30

#### Hive常用命令

2018-07-04 17:17:24