22
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

Rank: #1056
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


Rank: #7380

nice:)

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

Rank: #286
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
mvp_badge
MVP
Rank: #2
Solution

Hi Rudo,

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

Rank: #286
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
mvp_badge
MVP
Rank: #2
Solution

Hi Rudo,

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

Rank: #1056
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


Rank: #7380

nice:)

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

Rank: #286
Solution

Hi Rudo,

Try with this to get last day of current month:

AddDays( AddMonths( NewDate( Year(CurrDate()), Month(CurrDate()), 1 ), 1 ), -1 )
Rank: #286

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 :)