web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to pick random year in a date?

(0) ShareShare
ReportReport
Posted on by

I need to pick a random year in a date and date must be the 1-April year will change as per filter.

what kind of function will give me the result?  is that mkdate(); or another one?

Please help.

*This post is locked for comments

I have the same question (0)
  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: How to pick random year in a date?

    That is great, please make sure you verify helpful answers with the checkbox next to each post to close the thread.

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at
    RE: How to pick random year in a date?

    Hi,

    You can use the following job/code to generate random numbers for the years within the date range dateNull and dateMax using mkdate function.  Please let me know if anything is missing.

    static void RandomYear(Args _args)
    {
        int i;
        int randomNumber;
        RandomGenerate randomGenerate;
    
        randomGenerate = RandomGenerate::construct();
        randomGenerate.parmSeed(new Random().nextInt());
       // for (i = 1; i <= 5; i++)
        {
            randomNumber = RandomGenerate.randomInt(year(dateNull()), year(dateMax())); // Generates random number within the range datenull and dateMax
            info(strFmt("%1", mkDate(1,4,randomNumber)));
        //}
    }
  • Community Member Profile Picture
    on at
    RE: How to pick random year in a date?

    i have use mkdate() as int in last year 

  • Vilmos Kintera Profile Picture
    46,149 on at
    RE: how to pick random year in a date ?

    I have updated the example to use a C# namespace, which provides better random range functionality than standard AX.

    Kindly mark helpful answer as verified.

  • Suggested answer
    Vilmos Kintera Profile Picture
    46,149 on at
    RE: how to pick random year in a date ?

    How about this?

        System.Random   sysRand = new System.Random();
        int             years =  System.Convert::ToInt32(sysRand.Next(1900, 2154));
        info(strFmt('%1', mkDate(01, 04, years))); 


Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans