Finding Out the Date and Time the File Was Modified the File DateTime Function

If your procedure must check when a file was last modified, use the FileDateTime function:


Pathname is a string that specifies the file you want to work with and may include the drive and folder where the file resides. The function returns the date and time stamp for the specified file. The date and time format depends on the regional settings selected in the Windows Control Panel. Let's practice using this function in the Immediate window:

1. Enter in the Immediate window: ?FileDateTime("C:\config.sys")

When you press Enter, Visual Basic returns the date and time stamp in the following format:

5/4/2001 10:52:00 AM

To return date and time separately, use the FileDateTime function as an argument of the DateValue or TimeValue functions. For instance:

?DateValue(FileDateTime("C:\config.sys")) ?TimeValue(FileDateTime("C:\config.sys"))

2. Enter the following statement on one line in the Immediate window:

If DateValue(FileDateTime("C:\config.sys"))< Date then Debug.Print "This file was not modified today."

The Date function returns the current system date as it is set in the Date/Time dialog box accessed in the Windows Control Panel.

0 -1

Post a comment