Solved

LINQ DatetimeProblem in Sharepoint

Posted on 2011-03-10
8
679 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 500 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
Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

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

If you create your solutions on SharePoint sooner or later you will come upon a request to set  permissions of the item depending on some of the item's meta-data - the author, people assigned as approvers, divisions, categories etc. The most natu…
The vision: A MegaMenu for a SharePoint portal home page The mission: Make it easy to maintain. Allow rich content and sub headers as well as standard links. Factor in frequent changes without involving developers or a lengthy Dev/Test/Prod rel…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

691 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