[date_firstdayofweek]

Description

Link: [date_firstdayofweek]
Author: Jason Huck
Category: Date
Version: 8.x
License: Public Domain
Posted: Jul. 20, 2006
Updated: Aug. 02, 2007
More by this author...
Returns the date of the first day of the week for the given date. If no date is provided, it uses today's date. Optionally accepts a -starton parameter to indicate whether the week should start on Sunday (1) or Monday (2).

Parameters

-date date, optional The starting date from which to calculate. Defaults to today.
-starton integer, optional An integer representing Sunday (1) or Monday (2), for the day on which the week should start.

Sample Usage

date_firstdayofweek;

date_firstdayofweek( -date=date('7/20/2006'), -starton=2);
						

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
define_tag(
	'firstdayofweek',
	-namespace='date_',
	-opt='date', -type='date', -copy,
	-opt='starton', -type='integer',
	-priority='replace',
	-description='Returns the date of the first day of the week for the given date.'
);
	!local_defined('date') ? local('date') = date;
	#date->set( -hour=14, -minute=0, -second=0);
	
	!local_defined('starton') ? local('starton') = 1;
	(: 1, 2) !>> #starton ? #starton = 1;
	
	local('daynum') = integer(#date->format('%w'));
	
	if(#daynum == #starton);
		return(#date);
	else(#daynum < #starton);
		return(#date->add( -day=1)&);
	else;
		return(#date->subtract( -day=(#daynum - #starton))&);
	/if;
/define_tag;

 

Related Tags



Comments

08/02/2007, Jason Huck
Update
The tag now passes the source date by copy instead of reference so as not to inadvertently change the source date!
Email:


Password:



Newest

Most Popular