We help IT Professionals succeed at work.

How can I get the time interval between two dates (in seconds) in VBScript

mahno
mahno asked
on
Hi experts,

I have an easy question. I need to get the interval in seconds between two dates. At the moment my implementation is the following:

Function xxxDuration()
  ' tStarted contain starting time. this is global
  ' variable and it's initalizes before this function call
  tCurrentTime = Now
  tSeconds = CDate(tCurrentTime - tStarted)
  xxxDuration = Second(tSeconds) + Minute(tSeconds)*60 + Hour(tSeconds)*3600
End Function

The problem is that this function is working only in case if interval less than 24 hours. Would you mind to help me - how can implement the finction working for any interval?

ps: This is NOT homework!!! Just I'm not well expirianced in VBScript.

Thx in advance,
mahno
Comment
Watch Question

Software Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT
Commented:
Hi,

Try mySecond = DateDiff("s",FirstDate,SecondDate)

regards.

Author

Commented:
Opss... Thx, ryancys, I should read the help more attentively in future :-)

Thx.
Ryan ChongSoftware Tead Lead / Business Analyst / System Analyst / Data Engineer
CERTIFIED EXPERT

Commented:
Hi mahno,

Glad could help you, and

> I should read the help more attentively in future :-)

Yes, that's true for all of us in IT industry :)

regards.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.