;; 
;;=====================================================================================----- 
;; 
;;FUNCTION      GetFolderDate() 
;; 
;;AUTHOR        Allen Powell  
;;  
;;CONTRIBUTORS  Glenn Barnas 
;; 
;;VERSION       1.2 - 2017/03/25 
;; 
;;HISTORY       1.0 - 2005/02/24 - Initial Release 
;;              1.2 - 2017/03/25 - Fixed AM/PM to 24-hour conversion issue, added option 
;;                                 for alternate timestamp objects (finally!) 
;; 
;;ACTION        Gets the folder date and time 
;; 
;;RETURNS       A string in the format of "YYYY/MM/DD HH:MM:SS" 
;; 
;;SYNTAX        GetFolderDate(Folder [, Which]) 
;; 
;;PARAMETERS    Folder - Required - String 
;;              - Name of directory.  To get the date of a remote directory,  
;;              you must use an  administrative share (\\computername\c$\directory) 
;; 
;;              Which - allows requesting the modification, creation, or access datestamp. 
;;               0 - Last Modified Date-stamp (this is the default) 
;;               1 - Created Date 
;;               2 - Last Accessed Date-stamp 
;; 
;;DEPENDENCIES  FSO (File System Object) 
;; 
;;EXAMPLES      $folderdate=getfolderdate("c:\windows") 
;;              $folderdate=getfolderdate("\\remotepc\c$\windows") 
; 
Function GetFolderDate($_Folder, OPTIONAL $_Which)
 
  Dim $_Datetime				; the date/time string returned from FSO query 
  Dim $_Date					; Date in Kix standard format (YYYY/MM/DD) 
  Dim $_Time					; time string in Kix standard format (hh:mm:ss) 
 
  ; Get optional arg as number, defaulting to zero 
  $_Which = Val($_Which)
 
  ; Remove trailing slash from folder string 
  If Right($_Folder,1) = '\'
    $_Folder = SubStr($_Folder,1,Len($_Folder)-1)
  EndIf
 
  ; Verify folder exists, otherwise exist with "not found" 
  If Exist($_Folder)
    Select
     Case $_Which = 2
      $_DateTime = CreateObject('Scripting.FileSystemObject').getfolder($_Folder).DateLastAccessed
     Case $_Which = 1
      $_DateTime = CreateObject('Scripting.FileSystemObject').getfolder($_Folder).DateCreated
     Case 1
      $_DateTime = CreateObject('Scripting.FileSystemObject').getfolder($_Folder).DateLastModified
    EndSelect
 
    If @ERROR = 0
      ; reformat the time string to Kix standards (yyyy/mm/dd hh:mm:ss) 
      $_Date = Split($_DateTime, ' ')[0]
      $_Date = Split($_Date, '/')[2] + '/' + Right('0' + Split($_Date, '/')[0], 2) + '/' + Right('0' + Split($_Date, '/')[1], 2)
      $_Time = Split($_DateTime,' ')[1]
 
      ; Adjust the hour from AM/PM to 24-hour format. Don't change 12PM, and set 12AM to "00" 
      If Right($_DateTime,2) = 'PM' And Left($_Time, 2) <> '12'		; add 12 hours to the value after 12pm 
        $_Time = '' + (Val(Split($_Time, ':')[0]) + 12) + ':' + Split($_Time, ':')[1] + ':' + Split($_Time, ':')[2]
      EndIf
      If Right($_DateTime,2) = 'AM' And Left($_Time, 2) = '12'		; set 12AM to "00" 
        $_Time = '00' + SubStr($_Time, 3)
      EndIf
 
      $GetFolderDate = $_Date + ' ' + $_Time    
    Else
      Exit @ERROR
    EndIf
 
  Else
 
    Exit 2
 
  EndIf
 
EndFunction