Subtract one month from Datetime.Today

后端 未结 3 586
醉梦人生
醉梦人生 2021-02-06 21:56

I have a DateTimePicker in which I allow user to select month previous to the current year.

The problem is, that if the date is 1st January, it can\'t calc

3条回答
  •  执念已碎
    2021-02-06 22:00

    Just substract a month by 'adding` -1:

    var lastmonth = DateTime.Today.AddMonths(-1);
    

    See the MSDN documentation on DateTime.AddMonths.

提交回复
热议问题