Lasso Soft Inc. > Home

[lp_date_monthLastDay]

Linklp_date_monthLastDay
AuthorBil Corry
CategoryDate
Version8.x
LicensePublic Domain
Posted02 Dec 2005
Updated02 Dec 2005
More by this author...

Description

Returns the last day of a given month.  May specify the month and year either as a [date] or as -month and -year.  Omitting the month chooses current month.  Omitting the year choose current year.

Note: Requires [lp_date_leapyear]

Sample Usage

lp_date_monthlastday: -month=2, -year=2000;

returns:

29

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

[

define_tag:'lp_date_monthLastDay',
	-description='Returns the last day of a given month.',
	-priority='replace',
	-optional='date',
	-optional='month',
	-optional='year';

	local:'month_selected'=(date)->month;
	local:'year_selected'=(date)->year;

	// get date
	if: local_defined:'date' && #date->type == 'date';
		#month_selected = #date->month;
		#year_selected = #date->year;
	/if;
	if: local_defined:'month' && (integer:#month) >= 1 && (integer:#month) <= 12;
		#month_selected = integer:#month;
	/if;
	if: local_defined:'year' && (integer:#year) >= 1000 && (integer:#year) <= 9999;
		#year_selected = integer:#year;
	/if;
	
	select: #month_selected;
		case: 1;
			return: 31;
		case: 2;
			if: (lp_date_leapyear: #year_selected);
				return: 29;
			else;
				return: 28;
			/if;
		case: 3;
			return: 31;
		case: 4;
			return: 30;
		case: 5;
			return: 31;
		case: 6;
			return: 30;
		case: 7;
			return: 31;
		case: 8;
			return: 31;
		case: 9;
			return: 30;
		case: 10;
			return: 31;
		case: 11;
			return: 30;
		case: 12;
			return: 31;
	/select;
	return: 0; // error
/define_tag;

]

Related Tags

Comments

06 Feb 2006, Bil Corry

Possibly

In order to subtract one second, you would have to extract the month and year from the date passed, add one month (and possibly one year if December) to the date, make sure the time is set to midnight, then subtract some delta (I would recommend something safer than one second, like 12 hours), then extract the ->day and return it.

05 Feb 2006, Richard Moore

Another option

I believe a faster way is typically to get the first of the next month and subtract a second.

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft