How can I get current year and month in format YYMM minus one month.
Example current: 2003
Example (what I need): 2002
Need it to be string
How can I get current year and month in format YYMM minus one month.
Example current: 2003
Example (what I need): 2002
Need it to be string
Hi.
Today
will give you a DateTime of current date, so then you can use .AddMonths() on that to go back a month. Then, simply use .ToString(“dateformat”); date format is similar to the formats that Excel uses, but you can look this up by searching online for .net date formats
Here is the code you would end up using:
Today.AddMonths(-1).ToString("yyMM")
Hey man
I would setup a DateTime variable called todayDate and assign this to Day.Today. This will give you today’s date in date format.
Then use another DateTime variable called previousDate and assign it to todayDate.AddMonths(-1). This will subtract one month from todays date.
I would then create a string variable called outputDate and assign it to previousDate.toString(“yyMM”). This should give you the result your looking for in string format.
I hope this helps.
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.