Sign in to follow this  
Followers 0
MRB1752

Date Loop

2 posts in this topic

Hi, I have program that pulls data from a database based on the system time. I need to re-run these reports for certain months in the past. I am trying to create a loop that will change the system date run the program advance the day by run the program etc. My loop isn't working, probably because of the way I have $SaveDate set up but I am not sure how it should be.

#include <Date.au3>

;Save Current date

$SaveDate = _NowCalcDate()

_SetDate(1,11,2010)

$Date_end = "2010/11/30"

while(_NowCalcDate() <= $Date_end)

_DateAdd('d', 1, _NowCalcDate())

WEnd

Share this post


Link to post
Share on other sites



Welcome to the forums.

Try this.

#include <Date.au3>

Local $sNextDate, $aNextDate

;Save Current date
Local $sSaveDate = _NowCalcDate()
Local $aSaveDate = StringSplit($sSaveDate, "/", 2)

_SetDate(1, 11, 2010)
Local $Date_end = "2010/11/30"

Do
    ; Call function for current system's date.
    ConsoleWrite(_NowCalcDate() & @CRLF)

    ; Increment system's date
    $sNextDate = _DateAdd('d', 1, _NowCalcDate())
    $aNextDate = StringSplit($sNextDate, "/", 2)
    _SetDate($aNextDate[2], $aNextDate[1], $aNextDate[0])
Until _DateDiff("D", _NowCalcDate(), $Date_end) < 0

; Reset to original system's date.
_SetDate($aSaveDate[2], $aSaveDate[1], $aSaveDate[0])
ConsoleWrite(_NowCalcDate() & @CRLF)

Share this post


Link to post
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
Sign in to follow this  
Followers 0