861
Views
7
Comments
Solved
Get the last month given current month
Application Type
Traditional Web, Reactive

Hi. How do I get the last month and year given current month

eg i have 11 january 2021

how do i get output december 2020

and if i have 1 feb 2021 i should get january 2021

2021-02-11 14-19-01
Ivan Leitão
Solution

Hi,


I think You could use the Built-in functions for that, like this:

AddMonths(YOURDATE,-1) - this will give the YOURDATE minus one month.


Kind Regards,

Ivan


UserImage.jpg
Oskar Fenger

nice:)

2026-02-24 09-32-11
RUDO MURIEL MUNYAVI

Hi again. Thank you for the solution. Sorry to bother, what if i want to get the last day of the current month?

2022-10-17 06-51-09
Shweta Gedam
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
2026-02-24 09-32-11
RUDO MURIEL MUNYAVI
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Rudo,

You'd use the AddMonths() built-in Function, with a second parameter of -1, so it gives you the previous month.

2022-10-17 06-51-09
Shweta Gedam
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
2020-09-15 13-07-23
Kilian Hekhuis
 
MVP
Solution

Hi Rudo,

You'd use the AddMonths() built-in Function, with a second parameter of -1, so it gives you the previous month.

2021-02-11 14-19-01
Ivan Leitão
Solution

Hi,


I think You could use the Built-in functions for that, like this:

AddMonths(YOURDATE,-1) - this will give the YOURDATE minus one month.


Kind Regards,

Ivan


UserImage.jpg
Oskar Fenger

nice:)

2026-02-24 09-32-11
RUDO MURIEL MUNYAVI

Hi again. Thank you for the solution. Sorry to bother, what if i want to get the last day of the current month?

2022-10-17 06-51-09
Shweta Gedam
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
2026-02-24 09-32-11
RUDO MURIEL MUNYAVI
2022-10-17 06-51-09
Shweta Gedam

Hi Rudo,

AddMonths(YOURDATE,-1) function will give you date with day count also but in your use case it shows that you don't want day count to be displayed.

To fix this, you need to use AddMonths function with proper date format as below:

FormatDateTime(AddMonths(YOURDATE,-1),"MMMM yyyy")


Hope it helps, Thanks :)

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.