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 :
Microsoft Dynamics AX (Archived)

AX2012 LINQ - How to compare datetime

(0) ShareShare
ReportReport
Posted on by

hi everyone,

I'm newbie with the AX.

I'm using LinQ to get data from AX server.

Here are my codes:

 QueryCollection<ContactPerson> contact = new QueryCollection<ContactPerson>(provider);

var results2 = (from c in contact 
where c.ModifiedDateTime >= fromDate

with ModifiedDateTime is ValueType type.

 I also tried to use  the command Convert.ToDateTime( c.ModifiedDateTime) >= fromDate but it didn't work too.

Please help me to solve this problem.

Thank you very much.

*This post is locked for comments

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

    Could you please elaborate the description of your problem? "It didn't work" isn't very detailed.

  • Dick Wenning Profile Picture
    8,705 Moderator on at

    did you check this example

    msdn.microsoft.com/.../jj677293.aspx

  • Community Member Profile Picture
    on at

    yes Dick Wenning, I've checked that example but there is no example about where by datetime.

  • Community Member Profile Picture
    on at

    hi Martin Drab,

    I just want to filter with datetime. Could you please advise/sample how to filter?

    With command Convert.ToDateTime( c.ModifiedDateTime) >= fromDate, I have error is "IQueryable is not recognize Convert..."

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

    Thank you, "IQueryable is not recognize Convert" is more specific than "it didn't work", although I'm note sure if it was your original problem. It says that you're trying to convert a type that can't be converted.

    I suggest you use the select statement to return a single property and First() to return a single value instead of a collection.

  • Community Member Profile Picture
    on at

    I just want to filter by compare with DateTime type, how could I do?

  • dontran Profile Picture
    130 on at
    Microsoft.Dynamics.AX.Framework.Linq.Data.dll not support (not handled) convert type 
    DateTime X++ to system.Datetime of .Net

    I'm try add class: Class.DateTimeUtil.axproxy of AX to .Net with code but didn't work.

    var results2 = (from c in contact 
    where DateTimeUtil.parse(c.ModifiedDateTime.ToString()) >= fromDate

    P/s: The .NET Framework System.DateTime type and the X++ date type. FromSystem.DateTime, there is no marshaling to the X++ utcdatetime type, and there is no marshaling to the timeOfDay extended data type (which is an int).

  • dontran Profile Picture
    130 on at

    Another solution for filter with ModifieldDatime in AXProxy

    CustTable tbl = new CustTable();

    DateTime _fromdate,_todate ;

    _fromdate = Convert.ToDateTime("01-01-2015");

    _todate = Convert.ToDateTime("01-01-2016");

    QueryBuildDataSource queyBuildDataSource = query.addDataSource(tbl.TableId);

    QueryBuildRange queryBuildRange = queyBuildDataSource.addRange(61440);

    queryBuildRange.value = Global.queryRange(_fromdate, _todate);

    p/s: with 61440= ID of  field ModifieldDateTime in table CustTable of AX

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans