1

Topic: VBS/VBA Comparing of dates and time

Kind time of days!
Friends, there was here a sharp necessity  a script on VBS, debug from under VBA in Excel and here hour already I am angry.
Situation it is that, there are two dates
dtStart = "5/8/2018 OF 0:51:00 PM"
dtEnd = "5/8/2018 OF 0:56:59 PM"
To me they need to be compared to 3 date, as that so

If oFile. DateCreated> = dtStart And oFile. DateCreated <= dtEnd Then
'   
End If

Whether as it to turn more it is less beautiful in VBS?
Thanks!

2

Re: VBS/VBA Comparing of dates and time

strQwerty;
Probably, so:

If oFile. DateCreated> = CDate (dtStart) And oFile. DateCreated <= CDate (dtEnd) Then

Only it is necessary to be convinced still that DateCreated returns type Date

3

Re: VBS/VBA Comparing of dates and time

Explicitly to convert in type Date, using function CDate ():

dtStart = CDate ("5/8/2018 OF 0:51:00 PM")
dtEnd = CDate ("5/8/2018 OF 0:56:59 PM")

Then to compare:

If dtStart <= oFile. DateCreated And oFile. DateCreated <= dtEnd Then
'   
End If

4

Re: VBS/VBA Comparing of dates and time

The_Prist wrote:

to be convinced that DateCreated returns type Date

Judging by object names and properties, oFile is FSO.File. So here problems should not be.

5

Re: VBS/VBA Comparing of dates and time

The_Prist, thanks! All fulfilled as it is necessary!

6

Re: VBS/VBA Comparing of dates and time

Akina;
Indeed, thanks for the help)!