I want to compare two persian dates to find out which one is greater, I use this function :
public static List<MatchDrawHistory> GetAllMatchDrawHistory(string startDate, string endDate)
{
using (var db= new ReceiveSendEntitiesV5())
{
var matchDrawList = db.MatchDrawHistories.Where(x => String.CompareOrdinal(x.DrawStartDate,startDate)>=0 && String.CompareOrdinal(x.DrawEndDate , endDate) <=0).ToList();
return matchDrawList;
}
}
but it does not work, how can I do it?
EDIT: DrawStartDate and DrawStartDate are nvarchar(20) in DataBase, and these are persian date not gregorian date
First you need to convert your string date to DateTime. Assuming your string date is as yyyy/MM/dd, the conversion function can be as follow:
private static DateTime ParseDate(string date)
{
var pc = new PersianCalendar();
string[] arrDate = date.Split("/");
return pc.ToDateTime(Int32.Parse(arrDate[0]), Int32.Parse(arrDate[1]),
Int32.Parse(arrDate[2]), 0, 0, 0, 0);
}
Now you can use the following method to compare two dates:
private static bool Compare(DateTime firstDate, DateTime secondDate)
{
return firstDate >= secondDate;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With