Expansion of the date type adding an age method
Returns the age in years between two dates. If no date param is provided it uses the server date as now.
It typically answers the question "How old are you|the dog|my car". The answer is derived by comparing the given "Date of birth" param (dob) with today. An optional "now" param can be used to answer the question "How old where xx at a given date".
Parameters
-dob
date, required
Sample Usage
// Calls the date type directly
date('2000-02-28') -> age
date('2000-02-28') -> age(date('2010-08-25'))
// Calls the age method that in turn calls the date type
age(date('2000-02-28'));
age(date('2000-02-28'),date('2010-08-26'))
age(-dob=date('2000-02-28'),-dod=date('2010-08-27'))
age(-dob=date('2000-02-28'),-dod=date('2010-08-28'))
age(-dob=date('2000-02-28'),-dod=date('2010-08-29'))
age(-dob=date('2000-02-28'),-dod=date('2010-08-30'))
age(-dob=date('2000-02-28'))
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
<?Lasso
/**!
Experimental expansion of the date type adding an age method
Returns the age in years between two dates. If no date param is provided it uses the server date as now
*/
define date -> age(now::date = date) => {
return #now -> year - .year - (#now -> dayofyear >= .dayofyear ? 0 | 1)
}
/**!
Returns the age as years calculated between to dates.
*/
define age(dob::date, dod::date = date) => #dob -> age(#dod)
define age(-dob::date, -dod::date = date) => #dob -> age(#dod)
?>