[lp_date_monthLastDay]

Description

Link: [lp_date_monthLastDay]
Author: Bil Corry
Category: Date
Version: 8.x
License: Public Domain
Posted: Dec. 02, 2005
Updated: Jan. 01, 0001
More by this author...
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]

Parameters

-date date, optional Find the last day of the month of the given date.
-month integer, optional Month number (1 - 12) to use, default is current month.
-year integer, optional Year (4-digit) to use, default is current year.

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
[

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

02/06/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.
02/05/2006, deco rior
Another option
I believe a faster way is typically to get the first of the next month and subtract a second.
Email:


Password:



Newest

Most Popular

Support tagSwap.net