Hi,

I haven't had much experience with writing functions before. I have a situation where I want to know the number of seconds between two times, I am checking a roster of events against a list of when things actually happened (so 9:00 - 9:15 should equal 900, and 9:15 - 9:00 should equal 900). The following is the function I came up with (very basic). Can anyone tell me if there is a different way of doing this?

I haven't had much experience with writing functions before. I have a situation where I want to know the number of seconds between two times, I am checking a roster of events against a list of when things actually happened (so 9:00 - 9:15 should equal 900, and 9:15 - 9:00 should equal 900). The following is the function I came up with (very basic). Can anyone tell me if there is a different way of doing this?

Function TimeDiff(StartTime As Date, StopTime As Date)

Dim TempTime As Date

StartTime = FormatDateTime(StartTime, vbShortTime)

StopTime = FormatDateTime(StopTime, vbShortTime)

If StartTime > StopTime Then

TempTime = StartTime

StartTime = StopTime

StopTime = TempTime

End If

TimeDiff = DateDiff("s", StartTime, StopTime)

End Function

## Comment