How to Extract Date from DateTime Field in Dynamics Ax



Description:-

Here is the job which extracts the Date from DateTime Field.

static void getDate(Args _args)
{
    System.DateTime _dateTime;
    Date            _date;
    PurchTable      _purchTable;
    ;
    _purchTable = PurchTable::find("12/01761");
    _dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
    _date = _dateTime.get_Date();
    info(date2str(_date,-1,-1,-1,-1,-1,-1));
}

Note: if you get “Request for the permission of type ‘InteropPermission’ failed.” error, you need to use InteropPermission class:

static void getDate(Args _args)
{
  System.DateTime     _dateTime;
  Date                _date;
  PurchTable          _purchTable;
  InteropPermission   intPerm = new InteropPermission(InteropKind::ClrInterop);
  ;
  _purchTable = PurchTable::find("12/01761");
  intPerm.assert();
  _dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
  _date = _dateTime.get_Date();
  CodeAccessPermission::revertAssert();
  info(date2str(_date,-1,-1,-1,-1,-1,-1));
}

Related Posts

Thanks for comments.....

:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
:-?
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
$-)
(y)
(f)
x-)
(k)
(h)
cheer