2つの日付の間のいくつかのレコードを表示するビューをレンダリングしようとしています。パラメーターが渡されない場合、ビューは5日目から翌月の次の5日目までの1か月のレコードを表示する必要があります。
今私はそれをしました、しかし私は私のコードについて心配しています、これをする別の方法がありますか、つまり私のコードをより良く見せます。
var dateStart = new DateTime();
var dateEnd = new DateTime();
if(dateTime !=null)
{
dateStart = Convert.ToDateTime(dateTime);
dateEnd = new DateTime(dateStart.Year, dateStart.Month + 1, 5);
}
else
{
if (DateTime.Today.Day <= 4)
{
DateTime lastMonth = DateTime.Today.AddMonths(-1);
dateStart = new DateTime(lastMonth.Year, lastMonth.Month, 5);
dateEnd = new DateTime(dateStart.Year, dateStart.Month + 1, 5);
}
DateTime date = DateTime.Today;
dateStart = new DateTime(date.Year, date.Month, 5);
dateEnd = new DateTime(date.Year, date.Month + 1,5);
}