datetime comparison

Dec 7, 2009 at 7:37 PM

Hello, i need to select objects thats "createdon" attribute date is equal, for example, current date. I have tryed to compare object.createdon.date and my date string, it not works...  object.createdon.Value.StartsWith("mydate") throws exeption. Can anybody show to me example to do it?

thank you as always and sorry for my english

Coordinator
Dec 8, 2009 at 9:22 AM

This may work

from c in provider.Linq<contact>()
                          where c.createdon.UserTime == new DateTime(2008, 09, 02)
                          select c;

from c in provider.Linq<contact>()

where c.createdon.UserTime == new DateTime(2008, 09, 02)

select c;

Also some discussion here:

http://linqtocrm.codeplex.com/WorkItem/View.aspx?WorkItemId=5818

 

Dec 9, 2009 at 5:25 PM

Yes, i have seen this post, but what library i need to connect to have "usertime" property in my entity?

Coordinator
Dec 9, 2009 at 11:28 PM

It's in the CRM Helper classes in the SDK.

Jan 20, 2010 at 9:22 PM

If I want the equivalent to the CrmDateTime "on-or-after" operator, how would that look in LinqToCRM?

Jan 30, 2010 at 11:53 AM

friism, thank you for your answers. All it works, but i have new trouble... i need to retrieve objects with crmdatetime attribute, where month = mymonth and day = myday and year can be any. How can i go deeper then UserTime property? (such a UserTime.DayOfYear or s.e.)

Coordinator
Jan 30, 2010 at 3:13 PM
kib357 wrote:

i need to retrieve objects with crmdatetime attribute, where month = mymonth and day = myday and year can be any.

I'm not sure you can do those types of queries with FetchXML/LinqtoCRM. Can you do the query you want using the CRM "Advanced Find"? If so, please post the generated FetchXML( here's how to get it http://ronaldlemmen.blogspot.com/2006/11/using-advanced-find-for-fetchxml.html).

LinqtoCRM relies on FetchXML to execute queries, so it has to be doable in FetchXML before it's possible with LinqtoCRM.

As an alternative, you can retrieve superset of you records, do "ToList()" and then filter client-side.