argumentum Posted August 7 Posted August 7 (edited) ; #FUNCTION# ==================================================================================================================== ; Name...........: HourAmPm ; Description....: Converts a time in 24-hour format to AM/PM format. ; Syntax.........: HourAmPm( $sDateTime [, $sAmPm = "AM|PM" [, $iTrimRight = 0]] ) ; Parameters.....: $sDateTime - The time (with date or not) string with "HH:" in it. ; $sAmPm - [optional] The AM/PM representation (default is "AM|PM"). ; $iTrimRight - [optional] The number of characters to trim from the right of the result (default is 0). ; $iNoDate - [optional] Whether to omit the date from the output. Defaults to False. ; Return values .: Success: Returns the formatted date and time in AM/PM format. ; Failure: None. ; Author ........: argumentum ; Modified ......: ; Remarks .......: This function takes a 24-hour time string, converts it to AM or PM format, and returns the result with optional trimming. ; Related .......: ; Link ..........: https://www.autoitscript.com/forum/index.php?showtopic=213061 ; Example .......: MsgBox(64, "Converted Time", HourAmPm("12/31/1999 18:59:59")) ; =============================================================================================================================== Func HourAmPm($sDateTime, $sAmPm = Default, $iTrimRight = Default, $iNoDate = Default) Local $aAmPm = StringSplit((StringInStr($sAmPm, "|") ? $sAmPm : "AM|PM"), "|"), $sFormat = $aAmPm[2] Local $iHourPos = StringInStr($sDateTime, ":"), $sHour = StringMid($sDateTime, $iHourPos - 2, 2) Local $sDate = StringLeft($sDateTime, $iHourPos - 3), $sTime = StringTrimLeft($sDateTime, $iHourPos - 1) If $sHour < 12 Then $sFormat = $aAmPm[1] ; https://www.autoitscript.com/forum/index.php?showtopic=213061 $sHour = Mod($sHour, 12) If Not $sHour Then $sHour = 12 Return StringTrimRight((Int($iNoDate) ? "" : $sDate) & StringRight('0' & $sHour, 2) & $sTime, Int($iTrimRight)) & " " & $sFormat EndFunc ;==>HourAmPm ...am always looking for these ( because am disorganized ) and when I find them they are more than needed so, I decided to simplify it and flexibly-cate** it. All that's needed is the hour, the rest of the date-time string should be anything as long as there is a "HH:" in it. ; Examples: ConsoleWrite('- ' & HourAmPm("18:59") & @CRLF) ; - 06:59 PM ConsoleWrite('- ' & HourAmPm("18:59:59.999") & @CRLF) ; - 06:59:59.999 PM ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999") & @CRLF) ; - 1999/12/31 06:59:59.999 PM ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999", Default, 7) & @CRLF) ; - 1999/12/31 06:59 PM ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59", Default, 3) & @CRLF) ; - 1999/12/31 06:59 PM ConsoleWrite('- ' & HourAmPm("12/31/1999 18:59", "a|p") & @CRLF) ; - 12/31/1999 06:59 p ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999", Default, 7, True) & @CRLF) ; - 06:59 PM Don't remember seeing this approach anywhere so I decided to share it **flexibly-cate [verb] To make it flexible Edited August 7 by argumentum better ioa747, Numeric1, Danyfirex and 1 other 4 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
jchd Posted August 7 Posted August 7 Thanks. Nitpick: if hours is a single digit, a preceding space is eaten. I seem to recall that H, M & S format is 2 digit in all cases. "2025-08-07 0:0:0" returns "2025-08-0712:0:0 AM" but should probably be "2025-08-07 12:00:00 AM" Not that I use AM/PM ridiculous convention. 24h format, like metric units, should be mandatory everywhere. ioa747 1 This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
ioa747 Posted August 7 Posted August 7 (edited) Practical! Thank you for sharing it. ideas - thoughts Spoiler expandcollapse popup#include <Date.au3> ; Examples: ConsoleWrite('- ' & HourAmPm("18:59") & @CRLF) ConsoleWrite('- ' & HourAmPm("18:59:59.999") & @CRLF) ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999") & @CRLF) ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999") & @CRLF) ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59") & @CRLF) ConsoleWrite('- ' & HourAmPm("12/31/1999 18:59") & @CRLF) ConsoleWrite('- ' & HourAmPm("2025-08-07 0:0:0") & @CRLF) ConsoleWrite('- ' & HourAmPm("2025-08-07 0:0:0") & @CRLF) ConsoleWrite('- ' & HourAmPm() & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 0, "ante meridiem/post meridiem") & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 0, "midnight/midday") & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 0, "vorm./nachm.") & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 0, "π.μ./μ.μ.") & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 1, "오전/오후") & @CRLF) ConsoleWrite('- ' & HourAmPm(Default, 0, "a.m./p.m.") & @CRLF) Func HourAmPm($sDateTime = "", $iSignUpper = 1, $sSign = "AM/PM") Local $aSign = StringSplit($sSign, "/", 2) Local $sAM = ($iSignUpper ? StringUpper($aSign[0]) : StringLower($aSign[0])) Local $sPM = ($iSignUpper ? StringUpper($aSign[1]) : StringLower($aSign[1])) Local $sFormat = $sAM, $iHour, $sTimePart, $sDatePart ; If no time string is provided, use the current local time. ; Local $sNow = @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC If $sDateTime = "" Or $sDateTime = Default Then $sDateTime = _Now() ; _Now() to local format ; Separate date and time parts, if a space exists. Local $iSpacePos = StringInStr($sDateTime, " ", 0, -1) If $iSpacePos > 0 Then $sDatePart = StringLeft($sDateTime, $iSpacePos) & " " $sTimePart = StringRight($sDateTime, StringLen($sDateTime) - $iSpacePos) Else $sDatePart = "" $sTimePart = $sDateTime EndIf ; Find the position of the first colon in the time part. Local $iColonPos = StringInStr($sTimePart, ":") If $iColonPos = 0 Then Return $sDateTime & " (Error: Invalid time format)" ; Extract the hour from the time part. $iHour = Number(StringLeft($sTimePart, $iColonPos - 1)) ; Determine if it's AM or PM. If $iHour >= 12 Then $sFormat = $sPM ; Convert to 12-hour format. If $iHour > 12 Then $iHour -= 12 ElseIf $iHour = 0 Then $iHour = 12 EndIf ; Get the rest of the time string (minutes and seconds) correctly. $sTimePart = StringTrimLeft($sTimePart, $iColonPos - 1) ; Return the final string. Return $sDatePart & StringRight("0" & $iHour, 2) & $sTimePart & " " & $sFormat EndFunc ;==>HourAmPm Edited August 7 by ioa747 improvement I know that I know nothing
argumentum Posted August 7 Author Posted August 7 (edited) 3 hours ago, jchd said: Not that I use AM/PM ridiculous convention. 24h format, like metric units, should be mandatory everywhere. And !, I don't disagree. But I've been here for so long that my brain has a hard time..., feeling, what time it is. As far as time formats, the one that comes out of AutoIt's Date.au3 UDF is YYYY/MM/DD HH:MM:SS and this HourAmPm() is just for that scenario. I have become personally fond of the YYYY/MM/DD format and that !, should be mandatory everywhere too 2 hours ago, ioa747 said: If $iColonPos = 0 Then Return $sDateTime & " (Error: Invalid time format)" I added the "( yes, one more )" to the title, because there are a bunch of all encompassing AM/PM functions in the forum that I found to be "overengineered". I use this in my personal stuff: and is not American or any counties standard. Is AutoIt's standard that I liked, plus the AM/PM I did think of that ( $sSign = "AM/PM" ) , but I'll replace $iSignUpper with $sSign = "AM/PM", as it does make it more usable. That I'll change. Edited August 7 by argumentum English ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted August 7 Author Posted August 7 The function header is thanks to your "press F10" toy @ioa747 ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Solution argumentum Posted August 7 Author Solution Posted August 7 (edited) ConsoleWrite('- ' & HourAmPm("1999/12/31 18:59:59.999", Default, 7, True) & @CRLF) ; - 06:59 PM Added "NoDate" because in the pic shows a full date and time but also say in 90 minutes so, might as well exclude the date because, dah Edited August 7 by argumentum ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted Wednesday at 04:55 PM Posted Wednesday at 04:55 PM Is my understanding correct that the latest/greatest AutoIt version does not allow to translate date/time from am/pm format to 24 hours format? I searched the forum but couldn't find an answer. argumentum 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted Wednesday at 05:44 PM Author Posted Wednesday at 05:44 PM 32 minutes ago, water said: ...AutoIt version does not allow to translate date/time... I care to change it to AM/PM because everything is 24 hour based. Do you have a AM/PM scenario that needs to be switched to 24 hour format ? And what do you mean by "does not allow to translate date/time" ? _DateTimeFormat ( $sDate, $sType ) in the new release is expanded for AM/PM #include <Date.au3> ; Show current date/time in the pc's format ConsoleWrite('+ _NowCalc() >' & _NowCalc() & '<' & @CRLF) For $n = 0 To 7 ConsoleWrite('- _DateTimeFormat(_NowCalc(), ' & $n & ') >' & _DateTimeFormat(_NowCalc(), $n) & '<' & @CRLF) Next + _NowCalc() >2025/09/24 13:41:22< - _DateTimeFormat(_NowCalc(), 0) >9/24/2025 1:41:22 PM< - _DateTimeFormat(_NowCalc(), 1) >Wednesday, September 24, 2025< - _DateTimeFormat(_NowCalc(), 2) >9/24/2025< - _DateTimeFormat(_NowCalc(), 3) >1:41:22 PM< - _DateTimeFormat(_NowCalc(), 4) >13:41< - _DateTimeFormat(_NowCalc(), 5) >13:41:22< - _DateTimeFormat(_NowCalc(), 6) >< - _DateTimeFormat(_NowCalc(), 7) >< hmm !, I see what you mean !. Last I saw it worked but the release does not work. I'll look into it. SOLVE-SMART and Musashi 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted Wednesday at 05:59 PM Posted Wednesday at 05:59 PM On the german forum there is a guy who needs to translate date/time from AM / PM format to 24 hours format. His problem has already been solved, but I remember your thread in the engl. forum regarding AM / PM output formatting. I searched the forum for code to do the AM /PM > 24 hours translation - without success. So I decided to ask the master of date / time translation Musashi and argumentum 1 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted Wednesday at 06:20 PM Author Posted Wednesday at 06:20 PM tell him to change this line in Date.au3 ( remove the read-only on the file first ) ; If $sType < 0 Or $sType > 5 Or Not IsInt($sType) Then If $sType < 0 Or $sType > 7 Or Not IsInt($sType) Then I have no idea why/how it went like that. I guess that the "oops" is on me ? 🤷♂️ Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted Wednesday at 06:37 PM Author Posted Wednesday at 06:37 PM (edited) 41 minutes ago, water said: I searched the forum for code to do the AM /PM > 24 hours translation - without success. Ok, am getting better at screwing up 😅 That function ( _DateTimeFormat() ) does not do that. I'd have to look into it. 41 minutes ago, water said: So I decided to ask the master of date / time translation Like my AI tells me: "you think too much of me" I'd have to get my brain in gear for that and am already spread too thin as is right now. @SOLVE-SMART gave him a solution for that in the German forum that works well ? ( haven't tested it ), unless that is not what he needs or you'd like to include that functionality in this function too, to have an all encompassing function to handle everything. Nonetheless your post woke me up to the in the date UDF. Edit: 42 minutes ago, water said: His problem has already been solved, but I remember your thread in the engl. forum regarding AM / PM output formatting. ...I need some cafe... Edited Wednesday at 06:43 PM by argumentum oops Musashi and SOLVE-SMART 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted Wednesday at 06:45 PM Posted Wednesday at 06:45 PM 4 minutes ago, argumentum said: gave him a solution for that in the German forum that works well ? Yes, it works perfectly. He replied to Solve-Smart's post: "That's exactly what I was looking for". So I would wait for more users to ask for the AM /PM > 24 hours translation before thinking about adding this functionality to AutoIt. Thanks a lot for taking the time to look into this subject My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
argumentum Posted Wednesday at 07:01 PM Author Posted Wednesday at 07:01 PM @water... I'll get me some cafe, take a walk, ..something. I edited my post above. I took everything out of context. My brain is hooked on a work project and I can not do more than one thing at the time 3 minutes ago, water said: So I would wait for more users to ask for the AM /PM > 24 hours translation before thinking about adding this functionality to AutoIt. Ok. That addition to the Date.au3 UDF, was right there for the taking. All I did was to add the strings for options 6 and 7 ... Case 6 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm tt" EndIf Case 7 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm:ss tt" EndIf ... Now including the AM/PM to it, ...I'll need to be in a happy place ( no pressure ) to get my brain in gear for that. Now any and every one, is welcomed to present a _DateTimeFormat() that includes that. I'll ( well, the MVPs ) will look at it and say "yey/ney". Remember ( not just you ), that all these UDFs were scripts users of the forum coded and expanded with the participation of everyone. Don't be shy. Your nationforum needs you !. ( nowalways recruiting coders ) Musashi, SOLVE-SMART and ioa747 3 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
ioa747 Posted 22 hours ago Posted 22 hours ago (edited) Wanted something more, added ... ; If $sType < 0 Or $sType > 5 Or Not IsInt($sType) Then If $sType < 0 Or $sType > 7 Or Not IsInt($sType) Then ... Case 6 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm tt" EndIf Case 7 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm:ss tt" EndIf ... If (StringInStr($sDate, 'pm') > 0) Or (StringInStr($sDate, $sPM) > 0) Then If $asTimePart[1] < 12 Then $asTimePart[1] += 12 ElseIf (StringInStr($sDate, 'am') > 0) Or (StringInStr($sDate, $sAM) > 0) Then If $asTimePart[1] = 12 Then $asTimePart[1] = 0 EndIf ... $sDate Input date in the format "YYYY/MM/DD[ HH:MM:SS[ tt]]" ... 4 - Display a time using the 24-hour format (hh:mm). (conversion from am/pm format). 5 - Display a time using the 24-hour format (hh:mm:ss). (conversion from am/pm format). 6 - Display a time using the am/pm format (hh:mm tt). 7 - Display a time using the am/pm format (hh:mm:ss tt). completed New version arrive Edited 34 minutes ago by ioa747 simplify Musashi and argumentum 2 I know that I know nothing
ioa747 Posted 20 hours ago Posted 20 hours ago and a portable one, to be available ConsoleWrite("- " & _Time12hTo24h('08:70 PM') & @CRLF) ; -2 ConsoleWrite("- " & _Time12hTo24h('08:30 PM') & @CRLF) ; 20:30 ConsoleWrite("- " & _Time12hTo24h('12:00 AM') & @CRLF) ; 00:00 ConsoleWrite("- " & _Time12hTo24h('12:00:44 PM') & @CRLF) ; 12:00:44 ConsoleWrite("- " & _Time12hTo24h('7:5 pm') & @CRLF) ; 19:05 ConsoleWrite("- " & _Time12hTo24h('7:5 am') & @CRLF) ; 07:05 ConsoleWrite("- " & _Time12hTo24h('08:30') & @CRLF) ; 08:30 Func _Time12hTo24h($sTime) Local $sNewTime = StringStripWS($sTime, 8) Local Const $bPM = (StringInStr($sNewTime, 'pm') > 0) $sNewTime = StringReplace($sNewTime, "pm", "") $sNewTime = StringReplace($sNewTime, "am", "") Local $aTime = StringSplit($sNewTime, ':') If $aTime[0] < 2 Then Return SetError(1, 0, -1) Local $iHour, $iMin, $iSec $iHour = Number($aTime[1]) $iMin = Number($aTime[2]) If $iHour < 0 Or $iHour > 12 Then Return SetError(2, 0, -2) If $iMin < 0 Or $iMin > 59 Then Return SetError(2, 0, -2) If $bPM And $iHour < 12 Then $iHour += 12 If Not $bPM And $iHour = 12 Then $iHour = 0 $sNewTime = StringFormat("%02i:%02i", $iHour, $iMin) If $aTime[0] >= 3 Then $iSec = Number($aTime[3]) If $iSec < 0 Or $iSec > 59 Then Return SetError(2, 0, -2) $sNewTime &= StringFormat(":%02i", $iSec) EndIf Return $sNewTime EndFunc ;==>_Time12hTo24h argumentum 1 I know that I know nothing
argumentum Posted 15 hours ago Author Posted 15 hours ago (edited) #include <Date.au3> #include <SQLite.au3> #include <Debug.au3> ; Show current date/time in the pc's format Exit _DateTimeFormat_Compare() Func _DateTimeFormat_Compare() Local $aArray[10][8] $aArray[0][0] = " | 0 - date and/or time." $aArray[0][1] = " | 1 - long date, regional settings." $aArray[0][2] = " | 2 - short date, regional settings." $aArray[0][3] = " | 3 - time, regional settings." $aArray[0][4] = " | 4 - time 24-hour (hh:mm)." $aArray[0][5] = " | 5 - time 24-hour (hh:mm:ss)." $aArray[0][6] = " | 6 - time AM/PM (hh:mm tt)." $aArray[0][7] = " | 7 - time AM/PM (hh:mm:ss tt)." _DateTimeFormat_Test($aArray, _NowCalc(), @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 23:59:59", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59 AM", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59 PM", @extended) ReDim $aArray[@extended + 1][8] Local $sArray = _SQLite_Display2DResult($aArray, 0, True) ConsoleWrite($sArray) ClipPut($sArray) ; to share in the forum if there is an error _DebugArrayDisplay($aArray, "_DateTimeFormat()") EndFunc ;==>_DateTimeFormat_Compare Func _DateTimeFormat_Test(ByRef $aArray, $sNowCalc, $iRow = 0) For $n = 0 To 7 $aArray[$iRow + 1][$n] = " | " & _DateTimeFormat($sNowCalc, $n) Next Return SetError(0, $iRow + 1, "Testing, testing. 1, 2, 3.") EndFunc ;==>_DateTimeFormat_Test Lets call this script "the golden test", so that we can share results. Makes sense to report failures only as otherwise we would be spamming the living out of the forum. If it all worked well, ... add a like/thanks to the post with the patch to show you tested it and worked as expected. | 0 - date and/or time. | 1 - long date, regional settings. | 2 - short date, regional settings. | 3 - time, regional settings. | 4 - time 24-hour (hh:mm). | 5 - time 24-hour (hh:mm:ss). | 6 - time AM/PM (hh:mm tt). | 7 - time AM/PM (hh:mm:ss tt). | 9/25/2025 12:19:48 PM | Thursday, September 25, 2025 | 9/25/2025 | 12:19:48 PM | 12:19 | 12:19:48 | 12:19 PM | 12:19:48 PM | 12/31/2025 11:59:59 AM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 AM | 11:59 | 11:59:59 | 11:59 AM | 11:59:59 AM | 12/31/2025 11:59:59 PM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 PM | 23:59 | 23:59:59 | 11:59 PM | 11:59:59 PM | 12/31/2025 11:59:59 AM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 AM | 11:59 | 11:59:59 | 11:59 AM | 11:59:59 AM | 12/31/2025 11:59:59 PM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 PM | 23:59 | 23:59:59 | 11:59 PM | 11:59:59 PM This report may look ugly in the browser but you can copy it and paste it to an editor and it'll look as intended. It looks good to me. If after peer review there are no complains ( say: a month ), it'll go into beta. Thanks @ioa747 Also, it'll need the help file adjustments to explain it's functionality ( important ) Edited 14 hours ago by argumentum Musashi and ioa747 2 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Musashi Posted 8 hours ago Posted 8 hours ago (edited) 6 hours ago, argumentum said: It looks good to me. For me as well ! The regional settings for Germany are fine ! "Thanks" to the post with the patch from @ioa747 added. Edited 8 hours ago by Musashi ioa747 and argumentum 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
argumentum Posted 58 minutes ago Author Posted 58 minutes ago (edited) expandcollapse popup#include <Date.au3> #include <SQLite.au3> #include <Debug.au3> ; Show current date/time in the pc's format Exit _DateTimeFormat_Compare() Func _DateTimeFormat_Compare() Local $aArray[10][8] $aArray[0][0] = " | 0 - date and/or time." $aArray[0][1] = " | 1 - long date, regional settings." $aArray[0][2] = " | 2 - short date, regional settings." $aArray[0][3] = " | 3 - time, regional settings." $aArray[0][4] = " | 4 - time 24-hour (hh:mm)." $aArray[0][5] = " | 5 - time 24-hour (hh:mm:ss)." $aArray[0][6] = " | 6 - time AM/PM (hh:mm tt)." $aArray[0][7] = " | 7 - time AM/PM (hh:mm:ss tt)." _DateTimeFormat_Test($aArray, _NowCalc(), @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 23:59:59", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59 AM", @extended) _DateTimeFormat_Test($aArray, "2025/12/31 11:59:59 PM", @extended) ReDim $aArray[@extended + 1][8] Local $sArray = _SQLite_Display2DResult($aArray, 0, True) ConsoleWrite($sArray) ClipPut($sArray) ; to share in the forum if there is an error _DebugArrayDisplay($aArray, "_DateTimeFormat()") EndFunc ;==>_DateTimeFormat_Compare Func _DateTimeFormat_Test(ByRef $aArray, $sNowCalc, $iRow = 0) For $n = 0 To 7 $aArray[$iRow + 1][$n] = " | " & _DateTimeFormatEx_v2($sNowCalc, $n) Next Return SetError(0, $iRow + 1, "Testing, testing. 1, 2, 3.") EndFunc ;==>_DateTimeFormat_Test ;~ | 0 - date and/or time. | 1 - long date, regional settings. | 2 - short date, regional settings. | 3 - time, regional settings. | 4 - time 24-hour (hh:mm). | 5 - time 24-hour (hh:mm:ss). | 6 - time AM/PM (hh:mm tt). | 7 - time AM/PM (hh:mm:ss tt). ;~ | 9/25/2025 12:19:48 PM | Thursday, September 25, 2025 | 9/25/2025 | 12:19:48 PM | 12:19 | 12:19:48 | 12:19 PM | 12:19:48 PM ;~ | 12/31/2025 11:59:59 AM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 AM | 11:59 | 11:59:59 | 11:59 AM | 11:59:59 AM ;~ | 12/31/2025 11:59:59 PM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 PM | 23:59 | 23:59:59 | 11:59 PM | 11:59:59 PM ;~ | 12/31/2025 11:59:59 AM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 AM | 11:59 | 11:59:59 | 11:59 AM | 11:59:59 AM ;~ | 12/31/2025 11:59:59 PM | Wednesday, December 31, 2025 | 12/31/2025 | 11:59:59 PM | 23:59 | 23:59:59 | 11:59 PM | 11:59:59 PM Func _DateTimeFormatEx_v2($sDate, $sType) Local $asDatePart[4], $asTimePart[4] Local $sTempDate = "", $sTempTime = "" Local $sAM, $sPM, $sTempString = "" ; Verify If InputDate is valid If Not _DateIsValid($sDate) Then Return SetError(1, 0, "") EndIf ; input validation If $sType < 0 Or $sType > 7 Or Not IsInt($sType) Then Return SetError(2, 0, "") EndIf ; split the date and time into arrays _DateTimeSplit($sDate, $asDatePart, $asTimePart) Switch $sType Case 0 $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SSHORTDATE) ; Get short date format. If Not @error And Not ($sTempString = '') Then $sTempDate = $sTempString Else $sTempDate = "M/d/yyyy" EndIf If $asTimePart[0] > 1 Then $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIMEFORMAT) ; Get short time format. If Not @error And Not ($sTempString = '') Then $sTempTime = $sTempString Else $sTempTime = "h:mm:ss tt" EndIf EndIf Case 1 $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SLONGDATE) ; Get long date format. If Not @error And Not ($sTempString = '') Then $sTempDate = $sTempString Else $sTempDate = "dddd, MMMM dd, yyyy" EndIf If StringInStr($sTempDate, "'") Then ; dddd, d' de 'MMMM' de 'yyyy Local $aArray = StringSplit($sTempDate, "'") ; deconstruct string $sTempDate = $aArray[1] For $n = 2 To UBound($aArray) - 2 Step 2 $sTempDate &= "' '" & $aArray[$n + 1] Next EndIf Case 2 $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SSHORTDATE) ; Get short date format. If Not @error And Not ($sTempString = '') Then $sTempDate = $sTempString Else $sTempDate = "M/d/yyyy" EndIf Case 3 If $asTimePart[0] > 1 Then $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIMEFORMAT) ; Get short time format. If Not @error And Not ($sTempString = '') Then $sTempTime = $sTempString Else $sTempTime = "h:mm:ss tt" EndIf EndIf Case 4 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm" EndIf Case 5 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm:ss" EndIf Case 6 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm tt" EndIf Case 7 If $asTimePart[0] > 1 Then $sTempTime = "hh:mm:ss tt" EndIf EndSwitch ; Format DATE If $sTempDate <> "" Then $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_SDATE) ; Get short date format. If Not @error And Not ($sTempString = '') Then $sTempDate = StringReplace($sTempDate, "/", $sTempString) EndIf Local $iWday = _DateToDayOfWeek($asDatePart[1], $asDatePart[2], $asDatePart[3]) $asDatePart[3] = StringRight("0" & $asDatePart[3], 2) ; make sure the length is 2 $asDatePart[2] = StringRight("0" & $asDatePart[2], 2) ; make sure the length is 2 $sTempDate = StringReplace($sTempDate, "d", "@") $sTempDate = StringReplace($sTempDate, "m", "#") $sTempDate = StringReplace($sTempDate, "y", "&") $sTempDate = StringReplace($sTempDate, "@@@@", _DateDayOfWeek($iWday, $DMW_LOCALE_LONGNAME)) $sTempDate = StringReplace($sTempDate, "@@@", _DateDayOfWeek($iWday, $DMW_LOCALE_SHORTNAME)) $sTempDate = StringReplace($sTempDate, "@@", $asDatePart[3]) $sTempDate = StringReplace($sTempDate, "@", StringReplace(StringLeft($asDatePart[3], 1), "0", "") & StringRight($asDatePart[3], 1)) $sTempDate = StringReplace($sTempDate, "####", _DateToMonth($asDatePart[2], $DMW_LOCALE_LONGNAME)) $sTempDate = StringReplace($sTempDate, "###", _DateToMonth($asDatePart[2], $DMW_LOCALE_SHORTNAME)) $sTempDate = StringReplace($sTempDate, "##", $asDatePart[2]) $sTempDate = StringReplace($sTempDate, "#", StringReplace(StringLeft($asDatePart[2], 1), "0", "") & StringRight($asDatePart[2], 1)) $sTempDate = StringReplace($sTempDate, "&&&&", $asDatePart[1]) $sTempDate = StringReplace($sTempDate, "&&", StringRight($asDatePart[1], 2)) EndIf ; Format TIME If $sTempTime <> "" Then $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_S1159) ; AM designator. If Not @error And Not ($sTempString = '') Then $sAM = $sTempString Else $sAM = "AM" EndIf $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_S2359) ; PM designator. If Not @error And Not ($sTempString = '') Then $sPM = $sTempString Else $sPM = "PM" EndIf $sTempString = _WinAPI_GetLocaleInfo($LOCALE_USER_DEFAULT, $LOCALE_STIME) ; Time seperator. If Not @error And Not ($sTempString = '') Then $sTempTime = StringReplace($sTempTime, ":", $sTempString) EndIf If (StringInStr($sDate, 'pm') > 0) Or (StringInStr($sDate, $sPM) > 0) Then ; patch If $asTimePart[1] < 12 Then $asTimePart[1] += 12 ; patch ElseIf (StringInStr($sDate, 'am') > 0) Or (StringInStr($sDate, $sAM) > 0) Then ; patch If $asTimePart[1] = 12 Then $asTimePart[1] = 0 ; patch EndIf ; patch If StringInStr($sTempTime, "tt") Then If $asTimePart[1] < 12 Then $sTempTime = StringReplace($sTempTime, "tt", $sAM) If $asTimePart[1] = 0 Then $asTimePart[1] = 12 Else $sTempTime = StringReplace($sTempTime, "tt", $sPM) If $asTimePart[1] > 12 Then $asTimePart[1] = $asTimePart[1] - 12 EndIf EndIf $asTimePart[1] = StringRight("0" & $asTimePart[1], 2) ; make sure the length is 2 $asTimePart[2] = StringRight("0" & $asTimePart[2], 2) ; make sure the length is 2 $asTimePart[3] = StringRight("0" & $asTimePart[3], 2) ; make sure the length is 2 $sTempTime = StringReplace($sTempTime, "hh", StringFormat("%02d", $asTimePart[1])) $sTempTime = StringReplace($sTempTime, "h", StringReplace(StringLeft($asTimePart[1], 1), "0", "") & StringRight($asTimePart[1], 1)) $sTempTime = StringReplace($sTempTime, "mm", StringFormat("%02d", $asTimePart[2])) $sTempTime = StringReplace($sTempTime, "ss", StringFormat("%02d", $asTimePart[3])) $sTempDate = StringStripWS($sTempDate & " " & $sTempTime, $STR_STRIPLEADING + $STR_STRIPTRAILING) EndIf If StringInStr($sTempDate, "'") Then ; dddd, d' de 'MMMM' de 'yyyy Local $aArray2 = StringSplit($sTempDate, "'") ; reconstruct string $sTempDate = $aArray2[1] For $n = 2 To UBound($aArray) - 2 Step 2 $sTempDate &= $aArray[$n] & $aArray2[$n + 1] Next EndIf Return $sTempDate EndFunc ;==>_DateTimeFormatEx_v2 This version 2, fixes Spanish, Portuguese and who knows what other language were the date is as "Wednesday, 26 of September of 2025", that in Spanish is "viernes, 26 de septiembre de 2025". That " de " is a problem when you're replacing d ( as date ) and wreaks havoc. Fortunately M$ escapes these non-date strings with a "'". Please test this version as it will be the one for the next beta. Thanks. @ioa747, please remove yours to avoid confusion on which one we will use 🤔 Edited 50 minutes ago by argumentum English ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
water Posted 36 minutes ago Posted 36 minutes ago Tested with AutoIt 3.3.18.0 on a german W11 24H2 system. Works perfektly! argumentum 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now