Tuesday, September 15, 2009

How to populate a date variable

Some quick tips on how to populate a date variable.

Example 1: The use of function mkdate

TransDate myDate=mkdate(15,9,2009);

This function creates a date based on three integers, which indicate day, month and year. So mkdate(day,month,year).

As an alternative, you can use this:

Example 2: The use of function str2date

TransDate myDate=str2date('15/09/2009',123);

The function str2date converts a text string to a date value. The second argument gives the used formatting of the date string. (Where 1 stands for day, 2 for month and 3 for year.)

There is a similar function to create a DateTime value, namely str2datetime.
Use:

TransDateTime myDateTime=str2datetime( "15/09/2009 20:39:00" ,123 );

So, plenty of choice, whichever suits you.

3 comments:

  1. hi,

    how to read from the date dynamically from a date field on the form ...

    ReplyDelete
  2. hi,


    i want to know how many combinations are possible in AX for str2Date().

    are 9 combinations of dates format is possible in AX?

    ReplyDelete