我有一个财政年度的月末价值2。
如何根据该值计算财政年度的DateTime startDate和DateTime endDate?
发布于 2011-02-19 15:46:24
您可以执行以下操作:
DateTime startDate = new DateTime(DateTime.Today.Year, 2, 1); // 1st Feb this year
DateTime endDate = new DateTime(DateTime.Today.Year+1, 2, 1).AddDays(-1); // Last day in January next year这解决了你的问题吗?
发布于 2011-02-19 15:45:59
我猜你指的是2点的Feb。
这段代码应该做到这一点:
DateTime start = new DateTime(2010,2,1);
DateTime end = start.AddMonths(12).AddDays(-1);
Console.WriteLine(start);
Console.WriteLine(end);输出:
01-Feb-10 12:00:00 AM
31-Jan-11 12:00:00 AM发布于 2016-02-26 22:43:25
以下是我用于计算会计年度开始日期的版本。它将根据当前月份检查StartMonth,并将调整年份。
private DateTime? FiscalYearStartDate() {
int fyStartMonth = 2;
var dte = new DateTime(DateTime.Today.Year, fyStartMonth, 1); // 1st April this year
if (DateTime.Today.Month >= fyStartMonth) {
//Do nothing, since this is the correct calendar year for this Fiscal Year
} else {
//The FY start last calendar year, so subtract a year
dte = dte.AddYears(-1);
}
return dte;
}您可以像其他人一样轻松地计算结束日期,只需添加+1年,然后减去1天(多亏了约翰尼斯·鲁道夫)。
DateTime endDate = new DateTime(DateTime.Today.Year+1, 2, 1).AddDays(-1);https://stackoverflow.com/questions/5049562
复制相似问题