;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       StandardizedTime() 
;; 
;;ACTION         Convert a local timestamp to YYYY/MM/DD HH:MM:SS format for standard Kix processing 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0 - 2020/02/28 
;; 
;;HISTORY        1.0 - 2020/02/28 - Initial Release 
;; 
;;SYNTAX         StandardizedTime(Date, Time) 
;; 
;;PARAMETERS     Date - REQUIRED - date in localized format 
;; 
;;               Time - REQUIRED - Time in localized format 
;; 
;;REMARKS        Used to convert local date/time formats to standardized format for internal processing. 
;; 
;;RETURNS        String - Timestamp in YYYY/MM/DD HH:MM:SS format 
;; 
;;DEPENDENCIES   none 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16 
;; 
;;EXAMPLES        
; 
Function StandardizedTime($_Date, $_Time)
 
Shell '%COMSPEC% /c Echo Source: ' + $_Date + ' ' + $_Time 
 
  Dim $_Data							; the date time string in original format 
  Dim $_DFmt, $_DDlm						; localized date format and delimiter 
  Dim $_TFmt, $_TDlm						; localized time format and delimiter 
  Dim $_aResult[5]						; Result Array 
  Dim $_aModel, $_aData						; working arrays of format model, data 
 
 
  ; Get the LOCAL format & delimiter data 
  $_DFmt = ReadValue('HKEY_CURRENT_USER\Control Panel\International', 'sShortDate')
  $_DDlm = ReadValue('HKEY_CURRENT_USER\Control Panel\International', 'sDate')
  $_TFmt = ReadValue('HKEY_CURRENT_USER\Control Panel\International', 'sTimeFormat')
  $_TDlm = ReadValue('HKEY_CURRENT_USER\Control Panel\International', 'sTime')
 
  ; Define the model and data arrays 
  $_aModel = Split(Replace($_DFmt, $_DDlm, ' ') + ' ' + Replace($_TFmt, $_TDlm, ' '), ' ')
  $_aData  = Split(Replace($_Date, $_DDlm, ' ') + ' ' + Replace($_Time, $_TDlm, ' '), ' ')
 
  ; Process the DATE format 
  For $ = 0 to 2
    Select
     Case $_aModel[$] = 'M'                                     ; single digit month 
      $_aResult[1] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'MM'                                    ; Double digit month 
      $_aResult[1] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'd'                                     ; single digit day 
      $_aResult[2] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'dd'                                    ; single digit day 
      $_aResult[2] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'yy'                                    ; two digit year, add current century 
      $_aResult[0] = Left(@DATE, 2) + $_aData[$]
     Case $_aModel[$] = 'yyyy'                                  ; four digit year 
      $_aResult[0] = $_aData[$]
    EndSelect
  Next
 
 
  ; Process the TIME format 
  For $ = 3 To UBound($_aData)
    Select
     Case $_aModel[$] = 'tt'                                    ; format uses AM/PM 
      ; Handle midnight (12 AM => 00:) 
      If InStr($_aData[$], 'AM') And Int($_aData[3]) = 12 $_aResult[3] = '00' EndIf
      ; Handle PM hours > 12 
      If InStr($_aData[$], 'PM') And Int($_aData[3]) < 12
        $_aResult[3] = 12 + $_aResult[3]
      EndIf
     Case $_aModel[$] = 'h'                                     ; single digit hours 
      $_aResult[3] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'HH'                                    ; double digit hours 
      $_aResult[3] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'mm'                                    ; double digit minutes 
      $_aResult[4] = Right('00' + $_aData[$], 2)
     Case $_aModel[$] = 'ss'                                    ; double digit seconds 
      $_aResult[5] = Right('00' + $_aData[$], 2)
    EndSelect
  Next
 
  ; Build the standardized time format 
  $StandardizedTime = $_aResult[0] + '/' + $_aResult[1] + '/' + $_aResult[2] + ' ' + $_aResult[3] + ':' + $_aResult[4] + ':' + $_aResult[5]
 
  Exit 0
 
EndFunction