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

后端 未结 10 1533
眼角桃花
眼角桃花 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:00

    The canonical use case in e-commerce is credit card expiration dates, MM/yy. Subtract one second instead of one day. Otherwise the card will appear expired for the entire last day of the expiration month.

    DateTime expiration = DateTime.Parse("07/2013");
    DateTime endOfTheMonthExpiration = new DateTime(
      expiration.Year, expiration.Month, 1).AddMonths(1).AddSeconds(-1);
    

提交回复
热议问题