如何比较两个波斯日期以找出哪个更大?

2024-03-23

我想比较两个波斯日期以找出哪个更大,我使用这个函数:

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;
    }
}

但它不起作用,我该怎么办?

EDIT: DrawStartDate and DrawStartDate are nvarchar(20) in DataBase,这些是波斯日期而不是公历日期


首先你需要转换你的string日期到DateTime。假设你的字符串日期是年/月/日,转换函数可以表示为:

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);
}

现在您可以使用以下方法来比较两个日期:

private static bool Compare(DateTime firstDate, DateTime secondDate)
{
    return firstDate >= secondDate;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何比较两个波斯日期以找出哪个更大? 的相关文章

随机推荐