I am executing a VBS file that returns the modified date of another file:
Set objFS=CreateObject("Scripting.FileSystemObject")
Set objArgs = WScript.Arguments
strFile= objArgs(0)
WScript.Echo objFS.GetFile(strFile).DateLastModified
However I want the date to be formatted to dd/MM/yyyy before it is returned.
As demonstrated here and https://stackoverflow.com/a/21280396/603855, vou can use a .Net StringBuilder to solve all your formatting problem without depending on locales or doing extra/specific work:
output:
You could just take the date modified of the file and pick it apart a bit..
So if the last modified date was 11/30/2014, this would return 30/11/2014 regardless of regional PC settings (which FormatDateTime() ignores)
The value returned by
objFS.GetFile(strFile).DateLastModified
is a date/time value. You can format this into a string using a formatting or conversion function:This will format the date/time value into a short date. How this is done depends on your current regional settings. E.g. in some cultures you will have "MM/dd/yyyy" and in other cultures "dd-MM-yyyy" etc.
You can also get complete control over the formatting by extracting the day, month and year part and putting them together into a string: