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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing dates

Status
Not open for further replies.

spiveygb

Programmer
Jun 24, 2003
27
0
0
US
This is about to drive me nuts so any help is greatly appreciated. I have captured the datelastmodified value from files in a directory and stuck them into an array. I'm then comparing the file name and value from the array with corresponding values in a text file. I want to compare them and if the one in the text file is older, replace it with the value from the array. However, I receive the type mismatch error when using datediff. I've used datediff and sometimes get the same message. If I use vartype a value of 7(date) is returned. Someone please offer some suggestions so I can remain sane. Thanks.
 
can you show us some code involving the Datediff's that you used...

-DNG
 
Sure. I've broken apart the timestamp while trying to get a solution to this issue. Originally, I had only two variables; one for the timestamp of the file in the text file and the other for the timestamp of the file in the array. It's bailing on the formatdatetime statement. When In the original where I was directly comparing the entire timestamp I received the error at the datediff statment. Thanks.

Code:
strContent = objFile.ReadLine
					arrFileContents = Split(strContent, ",")
					fBasename = trim(fs.GetBaseName(arrFileContents(0)))
					for i = 0 to ubound(rvfcode)
						if ucase(trim(cstr(fBasename))) = ucase(trim(cstr(rvfcode(i)))) then
							dim datCurFile,datFileList
							dim timeCurFile, timeFileList

							datCurFile = formatdatetime(trim(arrFileContents(1)),2)
							datFileList = formatdatetime(trim(theTimes(i)),2)
							timeCurFile = formatdatetime(trim(arrFileContents(1)),4)
							timeFileList = formatdatetime(trim(theTimes(i)),4)

							intDateComp = datediff("d",datCurFile,datFileList)

							'if rvf on file is still the latest one then read into array
							'so we can write new txt file with updated contents
							if intDateComp < 0 Then
								intTimeComp = datediff("n",timeCurFile,timeFileList)
								if intTimeComp < 0 then
									theFiles(i) = arrFileContents(0)
									theTimes(i) = arrFileContents(1)
								end if
								exit for
							end if
						end if
					next
 
In the original version of the code (before this issue came up) I was trimming the var arrFileContents and then attempting to use CDate with no success. I received the same type mismatch error. Any other suggestions?
 
here is the thing...

when you are doing this...

datCurFile = formatdatetime(trim(arrFileContents(1)),2)

formatdatetime function wont work as it expects a date expression, but i guess arrFileContents are strings...may be you can make them date type by using # literals...i guess you know how to do that...

on the other i was suggesting to use CDate() because CDate() function takes in a string input...

-DNG
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top