Jump to content

_Dateadd not working


Go to solution Solved by Malkey,

Recommended Posts

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!

 

Link to comment
Share on other sites

  • Solution

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
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...