Siryx Posted June 18, 2018 Posted June 18, 2018 (edited) So what i need is a function that I pass a starting date into and it counts up to the current date. Example: 2009-05-30 2009-05-31 2009-06-01 ... 2018-06-18 How would I do that? I found the Date.au3 in the includes but I can't find anything close to a time object like I'm used to working with in Java. I just need some $date = setDate(2009-05-30) and from there I could just add a day every time. I need this to be in the very format I stated earlier and from what I can see everytime related to date and time is automatically changed to my german locale. €: I already tried setDate but instead it changed my PCs clock. Not quite what i was looking for Edited June 18, 2018 by Siryx
Siryx Posted June 18, 2018 Author Posted June 18, 2018 (edited) Oh man. So youre saying all I have to do is input the date in correct format then DateAdd one day every time? I feel a little dense for not searching better. Thanks! I was so focused on my Date object, I completely forgot the date I input already is the pendant to the Date Object I'm used to. Edited June 18, 2018 by Siryx
Siryx Posted June 18, 2018 Author Posted June 18, 2018 After a little bit of testing I found out the format is not the one I was looking for, after the _DateAdd I get slashes instead of hypens. I'm solving this with a string replace. Is there a better solution?
GPinzone Posted June 18, 2018 Posted June 18, 2018 Take a look at the _DateAdd page: https://www.autoitscript.com/autoit3/docs/libfunctions/_DateAdd.htm As far as formatting, maybe this will help? https://www.autoitscript.com/autoit3/docs/libfunctions/_DayValueToDate.htm The example code should point you in the right direction. Gerard J. Pinzonegpinzone AT yahoo.com
TheXman Posted June 18, 2018 Posted June 18, 2018 (edited) @Siryx 47 minutes ago, Siryx said: After a little bit of testing I found out the format is not the one I was looking for, after the _DateAdd I get slashes instead of hypens. I'm solving this with a string replace. Is there a better solution? "Better" is a relative term. What's "better" for you may not be "better" for someone else. With that said, StringReplace() is probably the quickest and easiest way to change the slashes to dashes in this specific case. However, for more complex date/time conversions or to use one conversion method throughout, you may be interested in using _Date_Time_Convert(). You can read more about the UDF using the link below. Edited June 18, 2018 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Subz Posted June 18, 2018 Posted June 18, 2018 American format is : mm/dd/yyyy I believe StringReplace would be the most easiest, otherwise you could use StringFormat, StringSplit. #include <Date.au3> Local $sStartDate = "2009/05/30" Local $sDateUpdate = $sStartDate Local $aDateUpdate = StringSplit($sStartDate, "/", 2) For $i = 1 To _DateDiff("D", $sStartDate, _NowCalc()) $sDateUpdate = StringReplace(_DateAdd("D", 1, $sDateUpdate), "/", "-") ConsoleWrite("StringReplace : " & $sDateUpdate & @CRLF) $aDateUpdate = StringSplit(_DateAdd("D", 1, _ArrayToString($aDateUpdate, "-")), "/", 2) ConsoleWrite("StringSplit : " & _ArrayToString($aDateUpdate, "-") & @CRLF) Next
jchd Posted June 18, 2018 Posted June 18, 2018 A bit simpler: #include <Date.au3> Local $sStartDate = "2009/05/30" Local $sNextDate For $i = 1 To 31 $sNextDate = StringRegExpReplace(_DateAdd("D", $i, $sStartDate), "(\d\d\d\d)/(\d\d)/(\d\d)", "$2-$3-$1") ConsoleWrite($sNextDate & @LF) Next 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)
Subz Posted June 18, 2018 Posted June 18, 2018 Simpler for who !!! I'm fairly sure this is simpler: #include <Date.au3> Local $sStartDate = "2009/05/30" Local $sDateUpdate = $sStartDate For $i = 1 To _DateDiff("D", $sStartDate, _NowCalc()) $sDateUpdate = StringReplace(_DateAdd("D", 1, $sDateUpdate), "/", "-") ConsoleWrite("StringReplace : " & $sDateUpdate & @CRLF) Next
jchd Posted June 18, 2018 Posted June 18, 2018 Remember the OP wants dates in mm/dd/yyyy format. 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)
Subz Posted June 18, 2018 Posted June 18, 2018 Was confused about that as well, but I think he meant yyyy-mm-dd which is why I said that wasn't the American date format in my first post. It appears they are just using StringReplace at the moment, see Siryx last post.
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