Tuesday, January 3, 2012

How to extract Date value from a DateTime field?

How to extract Date value from a DateTime field:
static void getDate(Args _args)
{
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
;
_purchTable = PurchTable::find("PO000008");
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
info(date2str(_date,-1,-1,-1,-1,-1,-1));
}
OR
static void getDate(Args _args)
{
System.DateTime _dateTime;
Date _date;
PurchTable _purchTable;
InteropPermission intPerm = new InteropPermission(InteropKind::ClrInterop);
;
_purchTable = PurchTable::find("PO000008");
intPerm.assert();
_dateTime = System.DateTime::Parse(dateTime2str(_purchTable.createdDateTime));
_date = _dateTime.get_Date();
CodeAccessPermission::revertAssert();
info(date2str(_date,-1,-1,-1,-1,-1,-1));
}
OR
Simply :)-
Instead of the third and second last lines you could use:
_dateTime = DateTimeUtil::date(_purchTable.createdDateTime); for the same result.

No comments: