decode_date(+DateNumber, ?Year, ?Month, ?Day)

Convert the date number back to a date in the form Year, Month and Day. A date number is an integer that uniquely identifies a single day since 1-1-1.

Because date numbers are integers they can be used in arithmetic expressions. For instance, get the date of the same day in the next week. First convert the date to a date number, add 7 to the date number and then convert the date number back to a date. This algorithm works even if you go from an old year to a new year.

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_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
decode_date(730485, Y, M, D). succeeds, the day number of the last day of 2000 (31-dec-2000) is 730485, this value is decoded again and the values of the variables Y, M, and D is:
Y = 2000
M = 12
D = 31
decode_date(1, Y, M, D). succeeds, the values of the variables is:
Y = 1
M = 1
D = 1
decode_date(1, Y, M, 2). fails because the value of the last parameter is not equal to the calculated value of 1

 

Exceptions  
The DateNumber parameter is not an integer a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect parameter
A parameter is not an integer nor a variable a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect parameter

 

 

info@trinc-prolog.com