이제는 두 개의 endDate (코드에서 10,15) 분의 값이 같은 startDate (25)에 대해 발생합니다.여러 날짜 차이가있는 코드 #
해결 방법 : 나는이 두 분 중에서 최소의 가치를 원합니다. 충돌하는 endDate에 의해 주어진 값. 나는 귀하의 질문에 제대로 나는 당신이 뭘 하려는지 이해하는 관리 생각되게되고에 위의 신사에 동의 않지만
public class DateController : Controller
public ActionResult date()
{
int allDiff;
List<int> list=new List<int>();
int flag = 0;
DateTime[] startDate = new DateTime[3];
startDate[0] = new DateTime(2011, 11, 5);
startDate[1] = new DateTime(2011, 11, 7);
startDate[2] = new DateTime(2011, 11, 25);
DateTime[] endDate = new DateTime[3];
endDate[0] = new DateTime(2011, 11, 10);
endDate[1] = new DateTime(2011, 11,15);
endDate[2] = new DateTime(2011, 11, 30);
DateTime Min= startDate.Min();
DateTime Max = endDate.Max();
TimeSpan span = Max - Min;
int total = span.Days;
ViewBag.globalTotal = total;
foreach (DateTime e in endDate)
{
foreach (DateTime s in startDate)
{
if (s >= e)
{
TimeSpan span1 = s - e;
allDiff = span1.Days;
list.Add(allDiff);
flag = 1;
}
else {
flag = 0;
}
}
if (flag == 1)
{
int m = list.Min();
ViewBag.dhiraj = m;
total = total - m;
list.Clear();
}
}
ViewBag.Total = total;
return View();
}
1 : 여기에 게시 된 모든 사람에게 도움이 필요합니다 .-) 2 : 귀하의 질문에 약간의 혼란이 있습니다. 너 정말 알고 싶어? – Fischermaen
여러 날짜 차이를 계산하고 싶습니다 ... diff에 겹치지 않는 날짜와 갭 b/w 두 개의 날짜가 포함되는 것을 포함합니다. startDate = 2011/11/05 및 2011/11/25 endDate = 2011/11/10 및 2011/11/20 출력은 10 일이어야합니다. – RollerCosta
다른 고려 사항 :: 겹침 ... startDate : 2011/11/05 및 2011/11/07 endDate : 2011/11/10 및 2011/11/15 필요 OUTPUT 10days – RollerCosta