Calculate the age of something in years, the first three parameters are the 'birth' year, the next three input parameters are the date for which the age must be calculated. The last parameter is unified with the calculated age in years.
This predicate is located in the file 'datetime.txt', use ensure_loaded/1 to include this file.
see also: age/7 day_number/4 day_of_week/2 datetime module decode_date/4 decode_datetime/7 decode_time/4 encode_date/4 encode_datetime/7 encode_time/2 encode_time/3 encode_time/4 ensure_loaded/1 first_week/2 leap_year/1 length_month/3 monday_of_week/3 monday_of_week/5 next_week/4 num_weeks_in_year/2 prev_week/4 reverse_day_number/4 start_of_week/3
| Example | |
| age(1971, 8, 18, 2001, 1, 28, Age). | the specified birthdate is 18 August 1971, the date for which
the age is calculated is 28 January 2001, the calculated value is 29 and is unified with
the variable Age, Age = 29 |
| age(1971, 8, 18, 2001, 9, 28, Age). | succeeds and the calculated age is 30, Age = 30 |
| age(1971, 8, 18, 2001, 9, 28, 60). | fails because the calculated Age is 30 years and this value cannot be unified with the value of the last parameter which is 60 years |
| Exceptions | |
| A parameter is not an integer | a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect argument |