Home > OS >  What is the equivalent DateAndTime.DateAdd in C#
What is the equivalent DateAndTime.DateAdd in C#

Time:06-16

I have an old code written in VB.Net and I am trying to convert it into c#. I am stuck on DateAndTime.DateAdd conversion for c#

DateAdd(DateInterval.Month, -1, Now).ToString("MMM")

This is my old vb.net code. It is getting the current month and subtracting - one month from it.

How do I achieve this c#?

CodePudding user response:

Use DateTime.AddMonths.

Pay attention:

Returns a new DateTime

var date = DateTime.Now.AddMonths(-1);
var stringDate = date.ToString("MMM");
  • Related