Current month minus 18 months

How to get current month minus 18 months i.e for example this is November2023 and I want to get May 2022 as output. and input should be first day of that month

@Sneha_1992

Syntax : now.AddMonths(-18).Month

Cheers!

Hi @Sneha_1992

currentDate: DateTime.Now
date18MonthsAgo : currentDate.AddMonths(-18)
firstDayOfPreviousMonth: new DateTime(date18MonthsAgo.Year, date18MonthsAgo.Month, 1)
Message Box: "First day of the month 18 months ago: " + firstDayOfPreviousMonth.ToString("MMMM, yyyyy")

currentDate, date18MonthsAgo, firstDayOfPreviousMonth is of datatype System.DateTime
Hope it helps!!

Hi @Sneha_1992

Try this

formattedDate = Now.AddMonths(-18).ToString("yyyy-MM-dd")

Hope this helps!!

@Sneha_1992

StartDate of type DateTime

StartDate =DateSerial(Now.AddMonths(-18).Year, Now.AddMonths(-18).Month, 1)

Hope this will help you

now.AddMonths(-18).ToString("MMM yyyy")

gives you the month with year
new datetime(now.AddMonths(-18).Year,now.AddMonths(-18).Month,1).ToString("dd/MM/yyyy")

gives you the date
image

1 Like

Hi @Sneha_1992

Refer this workflow for better understanding:


Sequence.xaml (7.3 KB)

Hope it helps!!

@Sneha_1992

Now.AddMonths(-18).ToString("yyyy-MM-dd")

Now.AddMonths(-18).ToString("MMMM yyyy")

grafik

YourDateTimeVar.AddDays(- (NowYourDateTimeVarDay - 1)).AddMonths(-18)

ADDED: When Time part needs to be 00:00:00 handling:
grafik

Thanks @Shiva_Nikhil

Same llike this how to get last day of the month of 18 months ago month.

1 Like

@Sneha_1992

new datetime(now.AddMonths(-18).Year,now.AddMonths(-18).Month,1).AddDays(-1).ToString("dd/MM/yyyy")

use this to get last day of the month which is 18 months ago