Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

MonthsEnd()

Can Anyone explain how monthsend() works with a simple example??????

1 Solution

Accepted Solutions
Not applicable
Author

Hi,

Monthend(date) returns end date of the month.

while Monthsend is a little complex function, but I will try my best to explain.

Syntax for monthsend is:

MonthsEnd(n, date [, shift = 0 [, first_month_of_year = 1]])

where n is period to divide a year and will refer to values which divides 12 perfectly (so, n can be 1, 2, 3, 4, 6)

monthsend ( 3, '2001-10-19', 0, 2 )

here n =3 i.e. 12/3 so, we have 4 periods in 1 year (for e.g take it as 4 quarters)

then date = 2001-10-19 (YYYY-MM-DD)

then shift = 0 i.e. we want it to return end date of the period in which this date falls. if we give -1 here that will give end date of the previous period and positive value say 1 will give end date of next period.

first_month_of_period = 2 i.e. our year starts from feb not from jan.

So, our 4 periods will be (feb - apr, may- jul, aug- oct, nov- jan)

this date (2001-10-19) is of Oct month which falls in aug - oct period and last date of that period will be 2001-10-31.

So, this will return (2001-10-31).

Hope this answers and explains you monthsend() function.

...

Ashutosh

View solution in original post

1 Reply
Not applicable
Author

Hi,

Monthend(date) returns end date of the month.

while Monthsend is a little complex function, but I will try my best to explain.

Syntax for monthsend is:

MonthsEnd(n, date [, shift = 0 [, first_month_of_year = 1]])

where n is period to divide a year and will refer to values which divides 12 perfectly (so, n can be 1, 2, 3, 4, 6)

monthsend ( 3, '2001-10-19', 0, 2 )

here n =3 i.e. 12/3 so, we have 4 periods in 1 year (for e.g take it as 4 quarters)

then date = 2001-10-19 (YYYY-MM-DD)

then shift = 0 i.e. we want it to return end date of the period in which this date falls. if we give -1 here that will give end date of the previous period and positive value say 1 will give end date of next period.

first_month_of_period = 2 i.e. our year starts from feb not from jan.

So, our 4 periods will be (feb - apr, may- jul, aug- oct, nov- jan)

this date (2001-10-19) is of Oct month which falls in aug - oct period and last date of that period will be 2001-10-31.

So, this will return (2001-10-31).

Hope this answers and explains you monthsend() function.

...

Ashutosh