好吧,所以這應該是簡單的真的,但似乎我不能得到我的頭。 我有一張名爲Dates的表格,它列出了從2012年開始直到最後的所有日期。現在,當客戶進行預訂時,我需要獲取開始日期和結束日期,以日期時間格式生成它們之間的範圍,並根據表中的等效日期檢查每個日期以查看容量。如果是這樣,那麼通過預訂要求減少容量。 到目前爲止,我有這樣的代碼:C#比較日期然後遞減
private List<DateTime> getDateRange(DateTime startDate, DateTime endDate)
{
if (startDate > endDate)
{
return null;
}
List<DateTime> rv = new List<DateTime>();
DateTime tmpDate = startDate;
do
{
rv.Add(tmpDate);
tmpDate = tmpDate.AddDays(1);
} while (tmpDate <= endDate);
return rv;
}
的代碼應該產生在日期範圍列表,後來在這個函數被調用:
public void checkDateRange(DateTime startDate, DateTime endDate)
{
//need to check each element in the list against the table DateTest:
//changing the parameters of parse will give error. Require type handling
//First, extract the elements:
DateTime StartingDate = DateTime.Parse("02/25/2007");
DateTime EndingDate = DateTime.Parse("03/06/2007");
foreach (DateTime date in getDateRange(StartingDate, EndingDate))
{
date.ToShortDateString();
}
//rest of code should go here...
}
在想更像檢索整套表DateTest,然後在一個循環(不知道哪個)我會去檢查如果x = y這些是日期。任何代碼插圖將不勝感激。問候,
你的問題是什麼? –
我不確定如何執行此計劃,我需要將開始日期和結束日期之間的日期範圍與數據庫中的日期範圍進行比較。 –
那麼...你有什麼問題?從數據庫中讀取?比較值?寫入數據庫? –