Tuesday, 13 September 2016

Date Effectiveness


  • I will start with the Current Business Date.
    Generally, I have used systemDateGet() which holds the logic business date of the system. There is one more function called today() which gives the actual machine date. So far I haven’t felt the need to use today() but if anyone needs, it is out there.
    systemDateGet()
    today()There is one global method called getSystemDateTime(); which sets the current UTC time as a utcdatetime type. Only DateTimeUtil::getSystemDateTimecompensates for the time zone of the user, so as a best practice we should use this one instead of systemDateGet()

  • There are functions out there which will allow you to get Day of Month, Month of Year, and so on.
    dayOfMth(systemdateget());
    dayOfYr(systemdateget());
    wkOfYr(systemdateget());
    mthOfYr(systemdateget());
    dayName(dayOfMth(systemdateget()));

  • When we need to get the next month, next year or may be next quarter, We have:
    nextMth(systemdateget());
    prevMth(systemdateget());
    nextYr(systemdateget());
    preYr(systemdateget());
    prevQtr(systemdateget());
    nextQtr(systemdateget());
    dateMthFwd(systemdateget(), 9);  // forward 9 months
    dateMthFwd(systemdateget(), -9);  // backward 9 Months

  • Creating your own date
    mkdate : Creates a date based on three integers, which indicate the day, month, and year, respectively.
    e.g. mkDate(09, 09, 1989);

  • Date to String conversion
    date2str(systemdateget(), 123, dateDay::Digits2, DateSeparator::Space, DateMonth::Digits2, DateSeparator::Space, DateYear::Digits4);There is one more method available in case we want to use the regional settings of the user.
    date2strUsr(systemdateget());
  • UTCDateTime conversion
    Just so that you know, values of type UTCDateTime are stored in the database in UTC time zone while in the User Interface UTCDateTime values are displayed in  a user preferred time zone.  And the regular Date and Time values are not related to any time zone, so both stored and displayed values are equal.

public static void utcDateTimeConversion()
{
utcDateTime dateTimeUTC;
date regularDate;
TimeOfDay regularTime;
dateTimeUTC = DateTimeUtil::utcNow();
// converting UTC date/time to regular user time zone date
regularDate= DateTimeUtil::date(DateTimeUtil::applyTimeZoneOffset(dateTimeUTC ,
DateTimeUtil::getUserPreferredTimeZone()));
// converting UTC date/time to regular user time zone time
regularTime= DateTimeUtil::time(DateTimeUtil::applyTimeZoneOffset(dateTimeUTC,
DateTimeUtil::getUserPreferredTimeZone()));
// converting date/time from user time zone to utc date/time
dateTimeUTC = DateTimeUtil::newDateTime(regularDate, regularTime,
DateTimeUtil::getUserPreferredTimeZone());
}
convert DateTime to Date
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));
}

date difference:
date2num(systemdateget()) - date2num(urtable.date);

OR

Static void DateDiff(Args _args)
{
    TransDate   d1,d2;
    int daysdiff;
    ;
    d1  = 31\12\2010;
    d2  = today();
    daysDiff = d2 - d1;
    info(strfmt("%1",daysDiff));
}

=IIF(Format(Fields!EnqDueDate.Value , "dd/MM/yyyy") = "01/01/1900"," ",Fields!EnqDueDate.Value)

No comments:

Post a Comment

POSTMAN D365

  Postman is useful to test the behavior of different OData class from/to D365FO. In this post we will see the steps to setup Postman with D...