Reputation: 11437
I have a script which reads all the files in a remote dir and sets the file object to the oldest file. It then writes that file's creation/modified date into another file.
Issue: It writes the date in a weird format - yyyy-dd-mm hh:mm:ss I want format yyyy-mm-dd hh:mm:ss
Option Explicit
Dim fso, path, file, recentDate, recentFile, objFileHandle
Set fso = CreateObject("Scripting.FileSystemObject")
Set recentFile = Nothing
For Each file in fso.GetFolder("\\remoteServer\Drive\Folder").Files
If (recentFile is Nothing) Then
Set recentFile = file
ElseIf (file.DateLastModified < recentFile.DateLastModified) Then
Set recentFile = file
End If
Next
Set objFileHandle = fso.OpenTextFile("\\remoteServer\Drive\Folder\oldestDateTime.Txt", 2, "True")
objFileHandle.Write(recentFile.DateLastModified)
objFileHandle.Close
Anybody have an idea how i can get the format i want?
Upvotes: 0
Views: 554
Reputation: 348
According to this site
objFileHandle.Write(FormatDateTime(recentFile.DateLastModified, vbShortDate))
Should go some way to giving you what you want.
Unless, of course, you're talking about locale-based formatting? See also this question: VBS objFile.DateLastModified and Date Format Settings and its answers
Upvotes: -1