Loftus Posted January 10, 2017 Share Posted January 10, 2017 I need to automate loading forms and want to use a series of past dates. _NowDate, _DateAdd and _NowCalcDate functions will do what I want with one exception; the date format. I need to return the format of mm/dd/yyyy, not yyyy/mm/dd. How can I do that? Link to comment Share on other sites More sharing options...
water Posted January 10, 2017 Share Posted January 10, 2017 Welcome to AutoIt and the forum! Please check Melba's date/time conversion UDF: My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kylomas Posted January 11, 2017 Share Posted January 11, 2017 (edited) Loftus, ...or roll your own... #include <GUIConstantsEx.au3> #include <GUIConstants.au3> #include <date.au3> Local $gui010 = GUICreate('Date Convert') Local $datein = GUICtrlCreateDate('', 10, 10, 200, 20) Local $sStyle = "yyyy/MM/dd" GUICtrlSendMsg($datein, $DTM_SETFORMATW, 0, $sStyle) GUICtrlCreateLabel('Converted date', 10, 50, 200, 20) Local $dateconvert = GUICtrlCreateLabel('', 10, 75, 200, 20, $ss_sunken) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $gui_event_close Exit Case $datein GUICtrlSetData($dateconvert, _convertdate(GUICtrlRead($datein))) EndSwitch WEnd Func _convertdate($str) Return StringRegExpReplace($str, '(\d\d\d\d)/(\d\d)/(\d\d)', '$2/$3/$1') ; Swap yyyy/mm/dd to mm/dd/yyyy EndFunc ;==>_convertdate kylomas edit: if you need to zero fill mm or dd then you can do this Return StringRegExpReplace(StringRegExpReplace($dtmDate, '(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2}).*', '$2/$3/$1 $4:$5:$6'), '(?<!\d)(\d/)', '0$1') Edited January 11, 2017 by kylomas code cleanup Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted January 11, 2017 Share Posted January 11, 2017 ...as does Test2() in the example on the StringRegExpReplace() page in the help file Link to comment Share on other sites More sharing options...
Loftus Posted January 11, 2017 Author Share Posted January 11, 2017 Thank you. I have the date formatting correctly but I cannot get the previous date to calculate like I can in other languages. Similar to DateAdd('d', -1, Date()). this calculates yesterday or n days in the past. Everything I can find about AutoIt _DateAdd refers to adding a date, not subtracting a date. Is it possible to subtract a date from a given date? Link to comment Share on other sites More sharing options...
water Posted January 11, 2017 Share Posted January 11, 2017 Specify a negative number of days to add. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki 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