Using IComparer For SharePoint Date Comparison
Ok, so I had this requirement come up from a friend, he wanted some help writing a virtual method that would allow him to compare to SharePoint dates. I am curious if there is a better way to write this, because what I ended up with was disappointing to me:
C#:
-
#region Namespace References
-
using System;
-
using System.Collections;
-
using Microsoft.SharePoint;
-
#endregion
-
-
namespace buenz.WebParts
-
{
-
public class spDateComparer : IComparer
-
{
-
#region Class Constructors
-
-
public SPDateComparer()
-
{
-
}
-
-
#endregion
-
-
#region Public Methods
-
-
public virtual int Compare(object firstObject, object secondObject)
-
{
-
SPListItem firstDate = ((SPListItem)firstObject);
-
SPListItem secondDate = ((SPListItem)secondObject);
-
-
if (((DateTime)firstDate["myDate1"]) <((DateTime)secondDate["myDate2"]))
-
{
-
return -1;
-
}
-
-
else if (((DateTime)firstDate["myDate1"])> ((DateTime)secondDate["myDate2"]))
-
{
-
return 1;
-
}
-
-
else
-
{
-
return 0;
-
}
-
}
-
-
#endregion
-
}
-
-
}
Related posts:
- SharePoint Security Helper Class
- SPView Field Comparison
- ToolPart Class With System.Reflection
- AspnetUsersinroles Partial Class
- AspnetPersonalizationallusers Partial Class
No Comments »
No comments yet.
RSS feed for comments on this post. TrackBack URL























Articles & Research
SharePoint Architecture
Research Methodology
Personal/Off-Topic
Article Or Research Filed Under 
