Jump to content
Sign in to follow this  

Date handling problem with _DateAdd

Recommended Posts

I need to make a function that adds up a day whenever it's called to a date I setted in a variable.

As you see, in this for loop, the date is always the same. How to solve it? And how to make the date format DD/MM/YYYY?

#include <Date.au3>
Global $date="2010/12/20"
Global $NewDate
for $i=1 to 5
$sNewDate = _DateAdd('d',1,$date)
MsgBox( 4096, "", "Today + 1 days:" & $sNewDate )
Edited by niubbone

Share this post

Link to post
Share on other sites

Not entirely sure I know what you are asking here, but I will give it a go.

If you are asking why the date displayed in the message box is not changing, well, because you are adding 1 day to $date in the For loop, and $date is not changing since you first declared it. Maybe make $NewDate = $date, and keep changing $NewDate in the loop.

To change the format... well, many ways to do this one. Looks like you are fairly new to this, so for my example we will just use StringRight, StringLeft, and StringMid for our format change.

This is what I came up with... Does that address your concerns?

#include <Date.au3>
Global $date = "2010/12/20"
Global $NewDate = $date
For $i = 1 To 5
    $NewDate = _DateAdd('d', 1, $NewDate)
    MsgBox(4096, "", "Today + 1 days:" & _Format($NewDate))
Func _Format($FDate)
    Return StringRight($FDate,2) & '/' & StringMid($FDate,6,2) & '/' & StringLeft($FDate,4)

Share this post

Link to post
Share on other sites

Well this was the purpose:


Btw I'm too tired to read the code and understand it now, i'll give a look tomorrow.

Many thanks for the help, works good!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...