如何比较两个波斯日期以找出哪个更大? [英] How to compare two persian date to find out which one is greater?
本文介绍了如何比较两个波斯日期以找出哪个更大?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想比较两个波斯日期,找出哪个更大,我使用此功能:
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?
DrawStartDate
和DrawStartDate
在DataBase
中是nvarchar(20)
,它们是波斯日期,而不是公历日期
DrawStartDate
and DrawStartDate
are nvarchar(20)
in DataBase
, and these are persian date not gregorian date
推荐答案
首先,您需要将string
日期转换为DateTime
.假设您的字符串日期为 yyyy/MM/dd ,则转换函数可以如下:
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;
}
这篇关于如何比较两个波斯日期以找出哪个更大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文