Link to home
Start Free TrialLog in
Avatar of LuisEstebanValencia
LuisEstebanValenciaFlag for Belgium

asked on

LINQ DatetimeProblem in Sharepoint

I have the following code, the commented line is the line that filters out all the rows I need, and its always returning me zero.

The PublishingDate is a date field in sharepoint, I just wonder how is the best way to fix the date issue, I guess that the date in sharepoint format is different than in the variable datetime.today

 

    var articlesqry = from row in articles
                                  where row.ItemLanguage.ToString() == (WebPart.Language == null ? DefaultLanguage : Language)
                                  && row.PromoteToFront == true
                                  //&& row.PublicationDate >= DateTime.Today
                                  orderby row.PublicationDate descending
                                  select row;
ASKER CERTIFIED SOLUTION
Avatar of GeorgeGergues
GeorgeGergues

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LuisEstebanValencia

ASKER

NO, that doesnt work, it filters me out everything., why would I convert a datetime field again to datetime?

Avatar of GeorgeGergues
GeorgeGergues

are you sure it is DateTime ?

At DEbug .

track those values on the debug window and see the values.
Yes Its I have been developing for 9 years in .net! and it seems that sharepoint just treats date values in a different format.
well , did you manage to convert to DateTime ?
ITS A  DATETIME, there is no need to convert to datetime a variable that is already datetime, and yes I even tried and it doesnt work because both fields are in different format, datetime.today doesnt have the same format of the sharepoint date values
that is my point it is not a DateTime type

You have to convert that to DateTime or convert your DateTime to SharePoint Time

You can use this Utility

Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDate
Time


Try it .
I think that method returns a string, I am not in the office but I will try that later.