Nearest completed quarter

后端 未结 7 1204
野性不改
野性不改 2021-01-02 00:03

Is there a C# function which will give me the last day of the most recently finished Quarter given a date?

For example,

var lastDayOfLastQuarter = So         


        
7条回答
  •  天命终不由人
    2021-01-02 00:12

    A simple function can calculate the last days of the most recently completed month:

    public static DateTime LastQuarter(DateTime date)
    {
        return new DateTime(date.Year, date.Month - ((date.Month - 1) % 3), 1).AddDays(-1);
    }
    

提交回复
热议问题