Pages

Wednesday, December 7, 2016

A dynamic query range for month to date (SysQueryRangeUtil)

Here is the code for creating a month-to-date filter:

public static str monthToDateRange(int relativeDays = 0)
{
    utcdatetime currentDateTime;

    currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), 
DateTimeUtil::getUserPreferredTimeZone());

    SysQueryRangeUtil::dateRange(
        dateStartMth(DateTimeUtil::date(currentDateTime)),
        DateTimeUtil::date(DateTimeUtil::addDays(currentDateTime, relativeDays)));
}

The code must be added to the SysQueryRangeUtil class.

Use it like (monthToDate(n)) where n is the number of days from today. So month-to-date-yesterday would for example be (monthToDate(-1)).

No comments: