Get a file's last modified date in VB6

There is a built in VB6 function for that - no need for FSO (although FSO is great for more advanced file operations)

From http://msdn.microsoft.com/en-us/library/aa262740%28VS.60%29.aspx

Dim MyStamp As Date
MyStamp = FileDateTime("C:\TESTFILE.txt")

Add a reference to the Microsoft Scripting Runtime (Project->References...) and use the following code:

Dim fso As New FileSystemObject
Dim fil As File

Set fil = fso.GetFile("C:\foo.txt")
Debug.Print fil.DateLastModified

This is definitely the easiest way to achieve what you are looking for.

Dim myString as String

Dim myDate As Date

myString = Format(FileDateTime("C:\TESTFILE.txt"), "dd-MM-yyyy")

myDate = MyString

If you dim your variable as a string, you can use the Format function to shorten the result to just the date.

If you need your variable to be declared as a Date then do as I have done above and declare that as a separate variable. Once the Format function has done its job, copy the String variable to the Date variable and you're done in two lines of code.

As simple as that.

Tags:

Vb6