date2int is date2num

Let’s say you have two dates and want to know how many days there are between these two dates. Searching through Dynamics AX developers help you will find that there is an explicit conversion called date2int. This sounds reasonable, we do want to convert our date to an int to get the number of days.

But if you try to use date2int you will find that this will generate an error when compiling that says:

This function has not been declared

Obviously date2int does not work as the developer help suggests. But what does?

It did some digging without any success until one of my colleagues suggested that I try date2num instead. This command is used in XAL for the exact same purpose. Sure enough this worked just fine.

Example code:

1
2
3
4
5
6
7
8
9
10
11
12
13
  static void FO_date2num(Args _args)
  {
      date    date1 = systemDateGet();        // Today
      date    date2 = systemDateGet() - 1;    // Yesterday
      int     i;
      ;
 
      // Today - Yesterday
      i = date2num(date1) - date2num(date2);
 
      print i;
      pause;
  }

Printout:

1

Last 5 posts in Development

Leave a Reply

Your email address will not be published. Required fields are marked *