如何计算财务年度月末值的财务年度开始和结束日期?

时间:2011-02-19 07:42:18

标签: c# datetime

我有一个财政年度的月末值2

我如何根据该值计算财务年度DateTime startDateDateTime endDate

5 个答案:

答案 0 :(得分:3)

你可以这样做:

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

这能解决您的问题吗?

答案 1 :(得分:2)

我认为你的意思是2月2日。

此代码应执行此操作:

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

答案 2 :(得分:1)

这是我用于计算会计年度开始日期的版本。它会检查当前月份的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天(感谢Johannes Rudolph)。

DateTime endDate = new DateTime(DateTime.Today.Year+1, 2, 1).AddDays(-1);

答案 3 :(得分:0)

如果您当前的日期是14/01/2021 那么印度财政年度是01/04/2020至31/03/2021

使用以下代码获得完美的输出。

DateTime CurrentDate = DateTime.Now;
int CurrentMonth = CurrentDate.Month;

if (CurrentMonth >= 4)//4 is the first month of the financial year.
{
txtFromDate.Text = new DateTime(CurrentDate.Year, 4, 1).ToString(CS.ddMMyyyy);
txtToDate.Text = new DateTime(CurrentDate.Year + 1, 4, 1).AddDays(-1).ToString(CS.ddMMyyyy);
}
else
{
txtFromDate.Text = new DateTime(CurrentDate.Year - 1, 4, 1).ToString(CS.ddMMyyyy);
txtToDate.Text = new DateTime(CurrentDate.Year, 4, 1).AddDays(-1).ToString(CS.ddMMyyyy);
}

答案 4 :(得分:0)

public  static (DateTime, DateTime) GetCurrentFinacialYearDateRange()
    {
        if(DateTime.Now.Month >= 7)
        {
            DateTime startDate = new DateTime(DateTime.Today.Year, 7, 1); // 1st July this year
            DateTime endDate = new DateTime(DateTime.Today.Year + 1, 7, 1).AddDays(-1); // Last day in June next year
            return (startDate, endDate);
        }
        else
        {
            DateTime startDate = new DateTime(DateTime.Today.Year-1, 7, 1); // 1st July this year
            DateTime endDate = new DateTime(DateTime.Today.Year, 7, 1).AddDays(-1); // Last day in June next year
            return (startDate, endDate);
        }
        
    }