Jump to content
Server Maintenance This Week. ×

LastDayOfMonth ( theDate, theDifference )


This topic is 5910 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Name & Parameters: [color:red][big] LastDayOfMonth ( theDate, theDifference ) [/big]

Description: Returns the date of the last day of a month, measured from the date (theDate) plus the number of months in the future (theDifference) from that date. All positive, whole numbers and zero are valid for “theDifference"

Sample Input:

LastDayOfMonth ( 12/2/2007 ; 2 )

Results:

2/29/2008

Recursive: no

Formula:

Let (

[ 



//The number of months ahead



Dif = theDifference ;



//The number of the month that's Dif months ahead + 1



endMonthPlusOne = Case (



Mod ( Month ( theDate ) + Dif ; 12 ) + 1 ≤ 12 ;

Mod ( Month ( theDate ) + Dif ; 12 ) + 1 ;

1

) ;



//The year of the month that's Dif months ahead + 1



endYearOfEndMonth = Case (



Month ( theDate ) + Dif + 1 ≤ 12 ;

Year ( theDate ) ;

Floor ( ( Dif + Month ( theDate ) + 1 ) / 12 ) + Year ( theDate )



)

];



GetAsDate ( endMonthPlusOne & "/1/" & endYearOfEndMonth ) - 1



)



/*Kent Searight, 2008

3rd Rock Data, LLC*/ 

Required Functions: N/A

Author(s): Kent Searight

Date: 02/27/08

Credits:

Disclaimer:

FM Forums does not endorse or warrantee these files are fit for any particular purpose. Do not post or distribute files without written approval from the copyright owner. All files are deemed public domain unless otherwise indictated. Please backup every file that you intend to modify.

Link to comment
Share on other sites

That's an interesting thread you refer to, Michael.

Well, now that I've recovered from the wind being taken out of my sails I'm pretty excited about this newfound knowledge. I can think of a couple more occasions in the past when I've unnecessarily complicated date calculations because I didn't realize the flexibility of the Date function.

Onward ho to smoother sailing! :

Link to comment
Share on other sites

This topic is 5910 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.