title: I have a code that displays oldest file name in a file directory, but how to modify that code so that it shows oldest file date instead of file name?
body: <p>The below code shows oldest file name in a file directory, but I am interested in knowing the oldest file date, but not the oldest file name. </p>
  
  <pre><code>Sub oldestdate()
  
  Range("G10").Value = GetOldestFile("xxxxx\yyyy\gggggg\uuuuuu")
  
  End Sub
  
  
  Public Function GetOldestFile(ByVal FileFolder As String, _
                                Optional ByVal FileMask As String = "*.*", _
                                Optional ByVal FullName As Boolean = True) As String
  
     Dim FoundFile        As String
     Dim FileDT           As Date
  
     Dim OldestFile       As String
     Dim OldestDT         As Date
  
     Dim FS As Object
  
     '// Get rid of any terminating '\' just to get to a known state
     If Right(Trim(FileFolder), 1) = "\" Then
        FileFolder = Left(FileFolder, Len(Trim(FileFolder)) - 1)
     End If
  
     '// Get First file found in described folder
     FoundFile = Dir$(FileFolder &amp; "\" &amp; FileMask)
  
     '// Default return date
     OldestDT = Now
  
     Set FS = CreateObject("Scripting.FileSystemObject")
  
     '// Loop through the rest of the files in that folder
     Do Until FoundFile = ""
  
        FileDT = FS.GetFile(FileFolder &amp; "\" &amp; FoundFile).DateCreated
  
        '// Compare Current File datetime with oldest found
        If FileDT &lt; OldestDT Then
           OldestFile = FoundFile
           OldestDT = FileDT
        End If
  
        '// Get next file
        FoundFile = Dir$
     Loop
  
     Set FS = Nothing
  
     GetOldestFile =  Format(OldestDT, "mm/dd/yyyy")
  
  End Function
  </code></pre>
  
  <p>Please check the code and let me know if you have any questions or comments.</p>