New version - 17 Jun 23
=======================
Added: Added 24hr unpadded H mask.
New UDF in zip below.
Changelog: Changelog.txt
Here is my version of a UDF to transform date/time formats. It is entirely self-contained and although it defaults to English for the month/day names, you can set any other language very simply, even having different ones for the input and output. You need to provide a date/time string, a mask to tell the UDF what is in the string, and a second mask to format the output - the masks use the standard "yMdhmsT" characters.
This is an example script showing some of the features:
#include <Constants.au3> ; Only required for MsgBox constants
#include "DTC.au3"
Global $sIn_Date, $sOut_Date
; Basic format
$sIn_Date = "13/08/02 18:30:15"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yy/MM/dd HH:mm:ss", "dddd, d MMMM yyyy at h:mm TT")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Note how day name is corrected
$sIn_Date = "2013082 Sun 12:15:45 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "dddd, dd MMM yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Note use of $i19_20 parameter to change century
$sIn_Date = "13/08/02 18:30:15"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yy/MM/dd HH:mm:ss", "dddd, d MMMM yyyy at h:mm TT", 10)
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
$sIn_Date = "18:30:15 13/08/02"
$sOut_Date = _Date_Time_Convert($sIn_Date, "HH:mm:ss yy/MM/dd", "h:mm TT on ddd d MMM yyyy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Just to show it works both ways
$sIn_Date = "Friday, 2 August 2013 at 6:30 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "dddd, d MMMM yyyy at h:mm TT", "dd/MM/yy HH:mm")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
$sIn_Date = $sOut_Date
$sOut_Date = _Date_Time_Convert($sIn_Date, "dd/MM/yy HH:mm", "dddd, d MMMM yyyy at h:mm TT")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Note false returns for non-specified elements
$sIn_Date = "6:15 P"
$sOut_Date = _Date_Time_Convert($sIn_Date, "h:m T", "yy/MM/dd HH:mm:ss")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Note use of "x" in place of actual spacing/punctuation
$sIn_Date = "Sun 12:15:45 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "dddxhhxmmxssxTT", "dddd HH:mm")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Output month/day strings changed to French
_Date_Time_Convert_Set("smo", "jan,fév,mar,avr,mai,juin,juil,août,sept,oct,nov,déc")
_Date_Time_Convert_Set("ldo", "dimanche,lundi,mardi,mercredi,jeudi,vendredi,samedi")
_Date_Time_Convert_Set("SDO", 3) ; Each short name is first 3 chars of equivalent long name
; Note as only the short day names are required, they could have been set directly:
; _Date_Time_Convert_Set("sdo", "dim,lun,mar,mer,jeu,ven,sam")
$sIn_Date = "20130716 Sun 12:15:45 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "ddd, d MMM yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; Output month/day strings changed to German
_Date_Time_Convert_Set("smo", "Jan.,Feb.,März,Apr.,Mai,Juni,Juli,Aug.,Sept.,Okt.,Nov.,Dez.")
_Date_Time_Convert_Set("ldo", "Sonntag,Montag,Dienstag,Mittwoch,Donnerstag,Freitag,Samstag")
$sIn_Date = "20130716 Sun 12:15:45 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "dddd, d MMM yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
; All strings reconverted to default English
_Date_Time_Convert_Set()
; As shown here
$sIn_Date = "20130716 Sun 12:15:45 PM"
$sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMd ddd hh:mm:ss TT", "ddd, d MMM yy")
MsgBox($MB_SYSTEMMODAL, "DTC Conversion", $sIn_Date & @CRLF & $sOut_Date)
And here is the UDF and example in zip format: DTC.zip
As always, happy for any comments.
M23