[vz_elapsedtime]

Description

Link: [vz_elapsedtime]
Author: Pier Kuipers
Category: Date
Version: 8.5.x
License: Public Domain
Posted: Jul. 25, 2008
Updated: Jul. 25, 2008
More by this author...
Given a date and optional time, this tag will return a string displaying its offset compared to the current time in the format "[n] [units] ago".

Parameters

-datetime date, required

Sample Usage

[vz_elapsedtime(field('creation_date'))]
-> '23 minutes ago'
-> '5 days ago'
-> '1 month ago'

If the tag would return "1 day ago", it changes the output to
-> 'yesterday'
						

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
if(!lasso_tagexists('vz_elapsedtime'));
	define_tag('elapsedtime',
		-description='given a date and optional time, this tag will return a string displaying its offset compared to the current time in the format "[n] [units] ago".',
		-namespace='vz_',
		-required='datetime',
		-Priority='Replace');
		local('timenow'=date);
		local('output'=string);
		local('timespans'=(array('year', 'month', 'week', 'day', 'hour', 'minute', 'second')));
		iterate(#timespans, local('tmp'));
			local('diff'=(date_difference(#timenow, #datetime, #tmp)));
			if(#diff > 0);
				if((#tmp=='day')&&(#diff==1));
					#output = 'yesterday';
				else;
					#output = #diff+' '#tmp+(#diff>1?'s')+' ago';
				/if;
				loop_abort;
			/if;
		/iterate;
		return(@#output);
	/define_tag;
/if;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net