Home > Software engineering >  VBA about the date of the two string type difference how many seconds for help
VBA about the date of the two string type difference how many seconds for help

Time:09-16

Dim stim, or etim as string
Stim=20170915102515
Or etim=20170915101515

How to evaluate difference how many seconds

CodePudding user response:

The DateDiff function
https://www.yiibai.com/vba/vba_datediff_function.html

CodePudding user response:

 Dim stimStr As String, etimStr As String 
Dim stim As the Date, or etim As Date
StimStr="20200915102515"
EtimStr="20190916101515"
Stim=CDate (Format (stimStr, "0000-00-00 00:00:00"))
Or etim=CDate (Format (etimStr, "0000-00-00 00:00:00"))

The Debug. Print stim
The Debug. Print or etim

The Debug. Print "seconds interval:"; DateDiff (" s ", stim, or etim)
Interval: Debug. Print "points"; DateDiff (" n ", stim, or etim)
The Debug. Print "interval."; DateDiff (" h ", stim, or etim)

The Debug. Print "day interval:"; DateDiff (" d ", stim, or etim)
The Debug. Print "month interval:"; DateDiff (" m ", stim, or etim)
Interval: Debug. Print "years"; DateDiff (" yyyy ", stim, or etim)

CodePudding user response:

refer to the second floor hitzsf response:
 Dim stimStr As String, etimStr As String 
Dim stim As the Date, or etim As Date
StimStr="20200915102515"
EtimStr="20190916101515"
Stim=CDate (Format (stimStr, "0000-00-00 00:00:00"))
Or etim=CDate (Format (etimStr, "0000-00-00 00:00:00"))

The Debug. Print stim
The Debug. Print or etim

The Debug. Print "seconds interval:"; DateDiff (" s ", stim, or etim)
Interval: Debug. Print "points"; DateDiff (" n ", stim, or etim)
The Debug. Print "interval."; DateDiff (" h ", stim, or etim)

The Debug. Print "day interval:"; DateDiff (" d ", stim, or etim)
The Debug. Print "month interval:"; DateDiff (" m ", stim, or etim)
Interval: Debug. Print "years"; DateDiff (" yyyy ", stim, or etim)

Thank you, the problem has been solved,
  •  Tags:  
  • VBA
  • Related