PhilipG Posted January 1, 2010 Share Posted January 1, 2010 Hi everyone I have a string that contains a date. The date is formated "yyyy/MM/dd". Is there any simple way to change the format to "d MMM -YY" Ifound something like _GUICtrlDTP_SetFormat() But that just seems to work on actual controls witch this isn't! Would be thankful over some help! Link to comment Share on other sites More sharing options...
KaFu Posted January 1, 2010 Share Posted January 1, 2010 Best way would be a RegEx, but this should also do it.... $sDate = "2009/12/31" $aDate = StringSplit($sDate,"/") $sDate_New = $aDate[3] & " " & $aDate[2] & " " & StringRight($aDate[1],2) MsgBox(0,"",$sDate & @crlf & $sDate_New) OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Malkey Posted January 1, 2010 Share Posted January 1, 2010 #include <Date.au3> ; "yyyy/mm/dd" to "d mmm-yy"format $sDate = "2009/12/01" $aDate = StringSplit($sDate, "/") $sDate_New = Number($aDate[3]) & " " & _DateToMonth($aDate[2], 1) & "-" & StringRight($aDate[1], 2) MsgBox(0, "Date Format", '"yyyy/mm/dd" = ' & $sDate & @CRLF & '"d mmm-yy" = ' & $sDate_New & @CRLF & "Reg Exp Rep = " & _ Execute(StringRegExpReplace($sDate, "(.{2})(.{2})/(.{2})/(.{2})", _ 'number("\4") & " " & _DateToMonth("\3", 1) & "-" & "\2"'))) Link to comment Share on other sites More sharing options...
Crash Posted January 1, 2010 Share Posted January 1, 2010 (edited) Try this: #include <DateTimeConstants.au3> ;For the date control $dateinput=GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY, 670, 67, 155, 20) ;Create the control- for reference $DTM_SETFORMAT_ = 0x1032 ;Will start to change the style $style = "d MMM yy" Edited January 1, 2010 by Crash JPGRAR | Mouse Lock | My website | Thanks so much for your help! ❤️ Link to comment Share on other sites More sharing options...
Malkey Posted January 1, 2010 Share Posted January 1, 2010 (edited) Try this: #include <DateTimeConstants.au3> ;For the date control $dateinput=GUICtrlCreateDate(@YEAR&"/"&@MON&"/"&@MDAY, 670, 67, 155, 20) ;Create the control- for reference $DTM_SETFORMAT_ = 0x1032 ;Will start to change the style $style = "d MMM yy" Here is another example of Crash's method. Local $Date = "1953/04/05 14:30:11.6" MsgBox(0, "Date Format", 'Date = ' & $Date & @CRLF & _ '"d MMM-yy" ' & @tab & " = " & _DateFormat($Date, "d MMM-yy") & @CRLF & _ '"dddd, d MMMM, yyyy" = ' & _DateFormat($Date, "dddd, d MMMM, yyyy") & @CRLF & _ '"dd/MM/yyyy" ' & @tab & " = " & _DateFormat($Date, "dd/MM/yyyy") & @CRLF & _ '"HH-mm-ss or h:mm tt"" = ' & _DateFormat($Date, "HH-mm-ss or h:mm tt")) Func _DateFormat($Date, $style) Local $hGui = GUICreate("My GUI get date", 200, 200, 800, 200) Local $idDate = GUICtrlCreateDate($Date, 10, 10, 185, 20) GUICtrlSendMsg($idDate, 0x1032, 0, $style) Local $sReturn = GUICtrlRead($idDate) GUIDelete($hGui) Return $sReturn EndFunc ;==>_DateFormat Edit: Added time element to MsgBox display for completeness. Edit2: Added GuiDelete to function as per KaFu's suggestion Post #6. Edited January 2, 2010 by Malkey Link to comment Share on other sites More sharing options...
KaFu Posted January 2, 2010 Share Posted January 2, 2010 (edited) Here is another example of Crash's method.Nice way . But better delete the GUI after the function is finished?Edit: For code see above Edited January 3, 2010 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
PhilipG Posted January 2, 2010 Author Share Posted January 2, 2010 Thanks alot! The problem is solved Link to comment Share on other sites More sharing options...
Crash Posted January 3, 2010 Share Posted January 3, 2010 Kafo: Wow, even a useless code can become a useful one when it's passed through your hands! PhilipG: Yohohohoho, I'm glad. Credits go to me!! Jk jk.. Credits still goes to others. I did nothing JPGRAR | Mouse Lock | My website | Thanks so much for your help! ❤️ Link to comment Share on other sites More sharing options...
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