Get the previous month's first and last day dates in c#

后端 未结 10 1515
眼角桃花
眼角桃花 2020-12-02 06:28

I can\'t think of an easy one or two liner that would get the previous months first day and last day.

I am LINQ-ifying a survey web app, and they squeezed a new requ

10条回答
  •  离开以前
    2020-12-02 07:06

    var today = DateTime.Today;
    var month = new DateTime(today.Year, today.Month, 1);       
    var first = month.AddMonths(-1);
    var last = month.AddDays(-1);
    

    In-line them if you really need one or two lines.

提交回复
热议问题