• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

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;
0
LuisEstebanValencia
Asked:
LuisEstebanValencia
  • 4
  • 4
1 Solution
 
GeorgeGerguesCommented:
Use the Convert .NET utility to set your types.
Does that work.


var articlesqry = from row in articles
                                  where row.ItemLanguage.ToString() == (WebPart.Language == null ? DefaultLanguage : Language)
                                  && row.PromoteToFront == true
                                  //&& Convert.ToDateTime(row.PublicationDate) >= DateTime.Today
                                  orderby row.PublicationDate descending
                                  select row;

BEst of Luck
0
 
LuisEstebanValenciaAuthor Commented:
NO, that doesnt work, it filters me out everything., why would I convert a datetime field again to datetime?

0
 
GeorgeGerguesCommented:
are you sure it is DateTime ?

At DEbug .

track those values on the debug window and see the values.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
LuisEstebanValenciaAuthor Commented:
Yes Its I have been developing for 9 years in .net! and it seems that sharepoint just treats date values in a different format.
0
 
GeorgeGerguesCommented:
well , did you manage to convert to DateTime ?
0
 
LuisEstebanValenciaAuthor Commented:
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
0
 
GeorgeGerguesCommented:
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 .
0
 
LuisEstebanValenciaAuthor Commented:
I think that method returns a string, I am not in the office but I will try that later.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now