Get last day of a month

CamiCat

Member
Hello friends,

How to get the last date of a month with out using any code stage?
I would like to get that only by passing as parameters the year and month, not the day.
Any ideas and suggestions appreciated.

Thanks,
Camilla.
 

jayp20

New Member
AddDays(AddMonths(MakeDate(1, [Month], [Year]), 1), -1)

MakeDate(1, [Month], [Year]), 1) : This makes a date of the first day of whatever month/year you pass as parameter.

AddMonths(MakeDate(1, [Month], [Year]), 1) : Adds 1 month so it is the first day of the next month

AddDays(AddMonths(MakeDate(1, [Month], [Year]), 1), -1) : Subtracts 1 day so it is now the last day of the original month you passed.
 

Jim

New Member
I would use the date add calculation, set the day as the first then use the inputs for the month and year. Add 1 month to that then minus 1 day
 

Jiri.Hurda

New Member
Hi Camilla,

This should work, If you want to pass Month and Year as inputs:

AddDays(AddMonths(MakeDate(1; [Month]; [Year]); 1); -1)

1) Make Date "1 - Month - Year" = creates the first day of month because of hardcoded 1st day
2) Add Month "1" to get next month's 1st day (in general you always have to use 1st day as kind a constant. Every month has the first day)
3) Add day "-1" to get the last day of the Month

So for example: Month = 2, Year = 2020
1) 01.02.2020
2) 01.02.2020 + 1 month = 01.03.2020
3) 01.03.2020 - 1 day = 29.02.2020
 
Last edited:
Top