Calculate the start-date and name of a quarter from a given date

前端 未结 8 1431
一向
一向 2020-12-23 14:07

How can I find the start-date and name (1, 2, 3, etc.) of a quarter from a given date?

8条回答
  •  南笙
    南笙 (楼主)
    2020-12-23 14:15

    DateTime date;
    int quarterNumber = (date.Month-1)/3+1;
    DateTime firstDayOfQuarter = new DateTime(date.Year, (quarterNumber-1)*3+1,1);
    DateTime lastDayOfQuarter = firstDayOfQuarter.AddMonths(3).AddDays(-1);
    

提交回复
热议问题