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:
- #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
- }
- }
Articles & Research
SharePoint Security
SharePoint Development
SharePoint Architecture
Claims Authentication
Forefront For SharePoint
AIS / Dynamics GP
Team Foundation Server
Pex And Moles
ISA/TMG/IAG/UAG
DPM
Cardspace
Research Methodology
Rural ICT Development
Numerical Analysis
Multi-Level Research
Knowledge Management
Personal/Off-Topic