In Dynamics AX, X++, how do you increment a date variable
Asked Answered
S

2

8

I am not sure if it is something with xslt or xpath..but how do I increment a date by 1 day? For example, if the date is 2/16/2009 I want the date to be incremented by 1 to become 2/17/2009 etc. etc.

Sorgo answered 22/5, 2009 at 16:36 Comment(2)
Care to give an example of what you want to accomplish?Bartko
increment a date by one what? second, minute, hour, day?Oleta
W
12

Incrementing a date variable in X++, Dynamics AX:

static void IncDate(Args _args)
{
    TransDate transDate = 16\02\2009;
    ;

    transDate++;

    print transDate;
    pause;
}

Result: 17/02/2009

Washington answered 9/3, 2011 at 9:29 Comment(2)
This seems like a very poor way to do it. Are you adding Days, Months, Years? Maybe minutes or seconds? The second answer here is much better.Bacon
A) Dates in AX are nothing else but the number of days passed from 01/01/1900. B) You cannot add minutes or seconds to date-typed variables. C) The question was clearly about incrementing by days. D) If you like the other answer feel free to upvote it, just bear in mind that it is about incrementing utcDateTime and not about incrementing a date, thus it's answering a different question. Useful to know anyway.Washington
M
4

DateTimeUtil::addDays

http://msdn.microsoft.com/en-US/library/cc552939(v=AX.50).aspx (AX 2009)

http://msdn.microsoft.com/en-us/library/datetimeutil.adddays.aspx (AX 2012)

Malaguena answered 2/1, 2012 at 10:12 Comment(1)
Note that this will add days to a utcdatetime type variable, but not to a date type variable. It is still useful, but does not answer the question of simply incrementing a date as the other answer does.Dialyse

© 2022 - 2024 — McMap. All rights reserved.