Solved

LINQ DatetimeProblem in Sharepoint

Posted on 2011-03-10
8
672 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
  • 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

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…
Pimping Sharepoint 2007 without Server-Side Code Part 1 One of my biggest frustrations with Sharepoint 2007 in the corporate world is that while good-intentioned managers lock down the more interesting capabilities of Sharepoint programming in…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

785 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