Jump to content

List every day from a starting day in american format


Recommended Posts

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 by Siryx
Link to comment
Share on other sites

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 by Siryx
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

@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 by TheXman
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Link to comment
Share on other sites

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 here
RegExp tutorial: enough to get started
PCRE 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)

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...