Sign in to follow this  
Followers 0
tybtech

_Dateadd not working

3 posts in this topic

Hello,

I'm trying to use the _dateadd function in a more complicated script, but the issue is the same even in the most simplifed script. For example:

#include <Date.au3>
#include <MsgBoxConstants.au3>

$cycles = 4
$stdt = "2015/01/31"
$repeat=1

Do

$stdt1 = _DateAdd('m', 1, $stdt)
$stdt1f = _DateTimeFormat($stdt1,2)
msgbox(0,'',$stdt1)
$stdt=$stdt1
$repeat += 1
Until $repeat = $cycles

My end goal is to have a variable that cycles forward 1 month every time the script repeats for a specified number of times. With the script I have right now, strangely the first time through, it cycles perfectly to 02/28/2015, but then the days get stuck and I get 03/28/2015 then 04/28/2015 and so forth. Help!

 

Share this post


Link to post
Share on other sites



Welcome

It appears you were progressively adding one month onto the previous answer. So  February 28 plus 1 month equals March 28.

#include <Date.au3>
#include <MsgBoxConstants.au3>

$cycles = 4
$stdt = "2015/01/31"
$repeat = 1

Do
    $stdt1 = _DateAdd('m', $repeat, $stdt)
    $stdt1f = _DateTimeFormat($stdt1, 2)
    MsgBox(0, '', $stdt1 & @CRLF & $stdt1f)
    ;$stdt = $stdt1
    $repeat += 1
Until $repeat = $cycles

Share this post


Link to post
Share on other sites

This was massively helpful. You figured out what I needed without me even properly asking what I needed! Thanks!

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