?
Solved

LINQ DatetimeProblem in Sharepoint

Posted on 2011-03-10
8
Medium Priority
?
680 Views
Last Modified: 2012-05-11
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
Comment
Question by:LuisEstebanValencia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 14

Accepted Solution

by:
GeorgeGergues earned 2000 total points
ID: 35095826
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
 

Author Comment

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

0
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35096920
are you sure it is DateTime ?

At DEbug .

track those values on the debug window and see the values.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:LuisEstebanValencia
ID: 35097654
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
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35097679
well , did you manage to convert to DateTime ?
0
 

Author Comment

by:LuisEstebanValencia
ID: 35099796
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
 
LVL 14

Expert Comment

by:GeorgeGergues
ID: 35099910
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
 

Author Comment

by:LuisEstebanValencia
ID: 35107082
I think that method returns a string, I am not in the office but I will try that later.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary In SharePoint 2010 it is easy to create custom color themes to jazz up a site. Theme colors can also be created in PowerPoint 2010 with a few clicks. But how do the chosen colors actually look in the SharePoint site? The attached PowerPoint…
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question