qwert Posted January 7, 2017 Share Posted January 7, 2017 Every now and then, I come upon the need to compare file dates. Then I realize that I don't have any snippet for the necessary conversions, so I search the help and forum for a simple call. Here's what I mean: FileGetTime returns YYYYMMDDHHMMSS ... which is great for comparing file dates. But when a user enters a date on a form and I read it (GUICtrlRead), there isn't a format option that matches the above. Even _NowCalc() doesn't have a matching choice. Is there a Au3 feature or call to convert an entered date to a "file date"? Or is there a different common denominator format that I should be using for date comparisons? Thanks in advance for help. Link to comment Share on other sites More sharing options...
czardas Posted January 7, 2017 Share Posted January 7, 2017 (edited) The date shown above can be interpreted in two different ways. Knowing the user's location would help, a bit. Although I haven't used it myself, you could try Melba's Date_Time_Convert UDF. https://www.autoitscript.com/forum/topic/154684-date_time_convert-bugfix-version-27-may-15/ I did some work on interpreting the format returned from the calendar control. You might be able to modify my code (it's rather complicated though, and I don't have much time to explain it). There's a lot of GUI code that you don't need: Edited January 7, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
qwert Posted January 7, 2017 Author Share Posted January 7, 2017 (edited) Thanks for your quick reply. Melba23's UDF is tantalizingly close. But I don't see anything that handles YYYYMMDDHHMMSS. This is why I get the uncomfortable feeling that I'm off the main path and am comparing dates the wrong way. BTW, the date I'm reading is formatted M/D/YYYY. Edited January 7, 2017 by qwert Link to comment Share on other sites More sharing options...
czardas Posted January 7, 2017 Share Posted January 7, 2017 Are all your users in the same country? If not then the order may change. You should be able to force the calendar control to always return the same format. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
qwert Posted January 7, 2017 Author Share Posted January 7, 2017 Quote Are all your users in the same country? Yes ... although I'm not wild about the way the date is formatted in the form's entry field. Having blanks only serves to confuse. But I haven't had time to see if there are alternatives. Link to comment Share on other sites More sharing options...
zone97 Posted January 7, 2017 Share Posted January 7, 2017 Maybe this could help some. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #Tidy_Parameters=/tc 3 /reel #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <DateTimeConstants.au3> #include <GuiDateTimePicker.au3> #include <Date.au3> #Region ### START Koda GUI section ### Form= $hGui = GUICreate("Date Picker", 285, 70, -1, -1) GUISetBkColor(0xC0C0C0) $hdate1 = GUICtrlCreateDate("", 16, 26, 250, 20) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### GUICtrlSetData($hdate1, _Now()) $hWndDate1 = ControlGetHandle($hGui, "", $hdate1) _GUICtrlDTP_SetFormat($hWndDate1, "MM/dd/yyyy") While 1 $msg = GUIGetMsg() Switch $msg Case -3 Quit() Case $hdate1 Create_File() EndSwitch WEnd Func Create_File() FileDelete("all_reports.acsauto") $date_array = StringSplit(GUICtrlRead($hdate1), "/") $yDate = $date_array[3] $mDate = $date_array[1] $dDate = $date_array[2] MsgBox(0, "Done", $yDate&$mDate&$dDate) EndFunc ;==>Create_File Func Quit() Exit EndFunc ;==>Quit Spoiler WinSizer 2.1 (01/04/2017) - Download - [ Windows Layout Manager ]Folder+Program (12/23/2016) - Download - [ USB Shortcut Creator ] Link to comment Share on other sites More sharing options...
czardas Posted January 7, 2017 Share Posted January 7, 2017 (edited) In my code you can find an example of forcing a four digit year in the control: ; force a four digit year in the date control GUICtrlSendMsg($idDate1, 0x1032, 0, LongYearFormat()) ; what is this magic? GUICtrlSendMsg($idDate2, 0x1032, 0, LongYearFormat()) ; https://www.autoitscript.com/forum/topic/93701-how-to-format-date-time-picker-selected-date/#comment-673255 [Melba23] and Func LongYearFormat() ; convert yy to yyyy Local $iID = _WinAPI_GetUserDefaultLCID(), _ $sFormat = _WinAPI_GetLocaleInfo($iID, $LOCALE_SSHORTDATE) $sFormat = StringRegExpReplace($sFormat, '(?i)(\byy\b)', 'yyyy') Return $sFormat EndFunc ;==> LongYearFormat With modification, you can force the calendar to always return mm/dd/yyyy (or similar). Then you can swap the order very easily. There are various ways you can do this. Edit: Or use DTP like @zone97 suggested. Edited January 7, 2017 by czardas zone97 1 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
qwert Posted January 7, 2017 Author Share Posted January 7, 2017 That's more like it! Date Picker solves the problem of blanks on the form ... and gives the format I need for comparisons. Thanks to you both. zone97 and czardas 2 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 7, 2017 Moderators Share Posted January 7, 2017 qwert, Quote Melba23's UDF is tantalizingly close. But I don't see anything that handles YYYYMMDDHHMMSS The UDF handles it very well - as you can see here: #include "DTC.au3" ; Convert from YYYYMMDDHHMMSS to M/D/YYYY $sIn_Date = "20170107123456" $sOut_Date = _Date_Time_Convert($sIn_Date, "yyyyMMddHHmmss", "M/d/yyyy") ConsoleWrite($sOut_Date & @CRLF) ; And back again $sIn_Date = $sOut_Date $sOut_Date = _Date_Time_Convert($sIn_Date, "M/d/yyyy", "yyyyMMdd000000") ; No time defined so force to "000000" ConsoleWrite($sOut_Date & @CRLF) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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