Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datediff compare in minutes

Status
Not open for further replies.

prinand

MIS
Jun 13, 2000
98
GB
question, I need to locate a file which is created the same minute or just 1 minute earlier /later.

I know where the "same" file is located so that all is no issue

So I just want to compare all files in that folder till I have found the right file.

So file array contains a listing of all the files in the folder I am searching:
fileArr(0,x) contains the filename
fileArr(1,x) contains the datemodified of the file

Function FindJobFile(date_time)
for x = 0 to IntFileArrSize - 1
if ABS(DateDiff("N",date_time,FileArr(1,x))) < 2 then
FindJobFile = FileArr(0,x)
exit for
End If
Next
End Function

now my question is : what happens if the timedifference is too big ?
I don't know if datediff output is a integer or a Longint, but the list I am looking in could contain hundreds or a few thousand files of which the first ones maybe 3 years older than the one I am trying to locate. however the datelastmodified is the only link I can make so I have to scan for this time difference.

or would it be better to nest the checks, and first check if the year is the same, than the month, than the day and as last step the datediff statement above ?
 
try it and see i would say.
the nested check might be a bit of a safetly net.
the thing you want to get right is that you dont want to loop through your array more than once (wait of time if you do)

+ so, perhaps you can remove an entry from your array if it doesnt match your criteria? that way at the end you are left with the results? which you can loop through and action?

+ or you can add your results to another array if you want to preserve your original data?

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top