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

Convert the date to a date number. 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 a certain day in the next week. First convert the date to a date number (use encode_date/4), add 7 to the date number and then convert the date number back to a date (use decode_date/4). 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_date/4 decode_datetime/7 decode_time/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
encode_date(2000, 12, 3, Num). succeeds, a daynumber is calculated for the date 3 dec 2000,
Num = 730457
encode_date(1, 1, 1, Num). succeeds, the calculated daynumber is 1
encode_date(1, 1, 1, 2). fails because the value of the last parameter is not equal to the calculated value of 1

 

Exceptions  
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