Store the last two digits of a year

I’m trying to get the last two digits of the year and store it as a variable, then concatenate it into a filepath. I was able to do something similar with the months, but it doesn’t seem to work for year. I tried using : DateTime.Now.AddMonths(-1).Year.ToString(“yy”) but it simply returns “yy” instead. Can anyone help?

Hi,

Can you try the following?

DateTime.Now.AddMonths(-1).ToString("yy")

Regards,

2 Likes

Hi,
Sure, you can do it like this:
DateTime.Now.Year.ToString.Substring(DateTime.Now.Year.ToString.Length-2)
or
Datetime.Now.ToString(“yy”)

Regards

1 Like

Hi, your solution worked! Thank you so much!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.