Hi,
I have two timestamps in the format yyyy-mm-dd hh24:mi:ss. I want to find the exact difference (sec level). Is there any in-buit routine that can I give me the difference. I know how to get that using Basics.
Thanks,
Girish Oak
How to find the difference between two timestamps
Moderators: chulett, rschirm, roy
This is the code from my own set of tools for KBATimestampDeltaSeconds, which takes two timestamps as arguments and returns to you the difference in seconds:
Code: Select all
StartDate = LEFT(Arg1,10)
StartTime = RIGHT(Arg1,8)
FinishDate = Left(Arg2,10)
FinishTime = RIGHT(Arg2,8)
InternalStartDate = ICONV(StartDate,"D-YMD[4,2,2]")
InternalStartTime = ICONV(StartTime,"MTS")
InternalFinishDate = ICONV(FinishDate,"D-YMD[4,2,2]")
InternalFinishTime = ICONV(FinishTime,"MTS")
NetDays = InternalFinishDate - InternalStartDate
NetTime = 0
Begin Case
Case InternalFinishTime >= InternalStartTime
NetTime = InternalFinishTime - InternalStartTime
Case InternalFinishTime < InternalStartTime
NetTime = ((24 * 60 * 60) - InternalStartTime) + InternalFinishTime
NetDays -= 1
End Case
* Number of days difference * 24 hours * 60 minutes * 60 seconds + number of seconds elapsed
TotalElapsedSeconds = (NetDays * 24 * 60 * 60) + NetTime
If TotalElapsedSeconds < 0 or NetDays < 0 Then TotalElapsedSeconds = 0
Ans = TotalElapsedSeconds
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Here's a version KBATimestampDeltaDays that gives you the answer rounded to days:
Code: Select all
StartDate = LEFT(Arg1,10)
StartTime = RIGHT(Arg1,8)
FinishDate = Left(Arg2,10)
FinishTime = RIGHT(Arg2,8)
InternalStartDate = ICONV(StartDate,"D-YMD[4,2,2]")
InternalStartTime = ICONV(StartTime,"MTS")
InternalFinishDate = ICONV(FinishDate,"D-YMD[4,2,2]")
InternalFinishTime = ICONV(FinishTime,"MTS")
NetDays = InternalFinishDate - InternalStartDate
NetTime = 0
Begin Case
Case InternalFinishTime >= InternalStartTime
NetTime = InternalFinishTime - InternalStartTime
Case InternalFinishTime < InternalStartTime
NetTime = ((24 * 60 * 60) - InternalStartTime) + InternalFinishTime
NetDays -= 1
End Case
* Number of days difference * 24 hours * 60 minutes * 60 seconds + number of seconds elapsed
TotalElapsedSeconds = (NetDays * 24 * 60 * 60) + NetTime
If TotalElapsedSeconds < 0 or NetDays < 0 Then TotalElapsedSeconds = 0
Ans = OCONV(TotalElapsedSeconds / (60 * 60 * 24), "MD0")
Kenneth Bland
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle
Rank: Sempai
Belt: First degree black
Fight name: Captain Hook
Signature knockout: right upper cut followed by left hook
Signature submission: Crucifix combined with leg triangle