web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Filter Data entity data generated within last 30 minutes

(0) ShareShare
ReportReport
Posted on by 401

Requirement: I need to create the data entity query range to filter data generated in the last 30 minutes

I have created a new method extending the SysqueryRange class like below and adding range on the data project window

public static str minuteRange(int relativeMinutesFrom = 0, int relativeMinutesTo = 0)
{
utcdatetime currentDateTime;
;

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

return SysQueryRangeUtil::dateRange(DateTimeUtil::date(DateTimeUtil::addMinutes(currentDateTime,relativeMinutesFrom)), DateTimeUtil::date(DateTimeUtil::addMinutes(currentDateTime,relativeMinutesTo)));
}

(minuteRange(-100, 0)).

I could get the entity work for days but not for the time.

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Your code is very difficult to read, because you've posted it in a wrong way. Please use Insert > Insert Code in the rich-formatting view.

    public static str minuteRange(int _relativeMinutesFrom = 0, int _relativeMinutesTo = 0)
    {
    	utcdatetime currentDateTime;
    
    	currentDateTime = DateTimeUtil::applyTimeZoneOffset(DateTimeUtil::getSystemDateTime(), DateTimeUtil::getUserPreferredTimeZone());
    
    	return SysQueryRangeUtil::dateRange(
    		DateTimeUtil::date(DateTimeUtil::addMinutes(currentDateTime, _relativeMinutesFrom)),
    		DateTimeUtil::date(DateTimeUtil::addMinutes(currentDateTime, _relativeMinutesTo)));
    }

    I think I see your problem - and it's not specific to data entities. You add minutes to the current date time, but then you convert all date time values to dates, therefore you're throwing away all information about hours, minutes and seconds.

  • SKO Profile Picture
    401 on at

    Thanks Martin, What would be the correct code to just return minutes

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    Hmm, what do you mean by just returning minutes? I thought your intention was just adding minutes to the current date time and making a range from those two values. Both would still have a year, a month, a day and so on, not only minutes. Is that what you want?

    If so, the first step is removing the calls of DateTimeUtil::date() - that's where you're removing hours, minutes and seconds.

    The other step is using a range method for datetime values - SysQueryRangeUtil::dateRange() is just for days. Unfortunately I don't remember if there is such a method (or you need to write the code directly in your method) and if it is, what is its name. If you fail to solve it, I can take a look at work tomorrow.

  • SKO Profile Picture
    401 on at

    I thought your intention was just adding minutes to the current date time and making a range from those two values. Both would still have a year, a month, a day and so on, not only minutes. Is that what you want? - Yes correct

    Sorry for vague reply.

    There is no method for minuteRange(), I am trying to add it and this is where the problem is.

    When you get chance please send me the solution.

    Thanks for the quick reply, much appreciated!!

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    You shouldn't be looking for anything like minuteRange() at all. You don't want an interval of minutes; you want an interval of datetime values.

  • Martin Dráb Profile Picture
    237,965 Most Valuable Professional on at

    At the first glance, I don't see a range for utcDateTime values. But you can easily add the logic by yourself; just look at how dateRange() does it:

    if (_startDate <= _endDate)
    {
    	result = SysQueryRangeUtil::value(_startDate)   '..'   SysQueryRangeUtil::value(_endDate);
    }
    else
    {
    	result = SysQueryRangeUtil::value(_endDate)   '..'   SysQueryRangeUtil::value(_startDate);
    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 450 Super User 2025 Season 2

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 278 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans