Date for last year manipulate

Hello Team,

1)How can we get the date if we provide

Current year:2023
Month:11
Date:02

How do we fetch the year , month , date of last year
Current year:2022
Month:11
Date:02
Starting Month Name: Noviembre(Because month given as 11)

2)How to get the year from file name

Example: Asno_Slate_data_2023_20231232

How do we extract just 20231232 from this file name

Hi @NISHITHA ,

Could you check the below Expressions :

(new DateTime(2023,11,02)).AddYears(-1)
System.Globalization.CultureInfo.GetCultureInfo("es-ES").DateTimeFormat.MonthNames(10)
Split("Asno_Slate_data_2023_20231232","_").Last

From Debug :
image

Thanks @supermanPunch for the quick resolution

1 Like

Now.AddYears(-1).Month (although this will be the same as your input date)
Now.AddYears(-1).Day (although this will be the same as your input date)
Now.AddYears(-1).Year (although this will be the same as your input year minus 1)
Now.AddYears(-1).ToString(“MMMM”) will give you the month name

2)How to get the year from file name

Example: Asno_Slate_data_2023_20231232

If you know it’ll always be that format, with the year the last value and _ before it, then you can just get it with string manipulation:

Split(Path.GetFilenameWithoutExtension(yourPath),“_”).Last

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