encode_datetime(+Year, +Month, +Day, +Hour, +Min, +Sec, date_time(?DateNumber, ?TimeNumber))

Convert the date and time parameters to a date- and time number. A date number is an integer that uniquely identifies a single day since 1-1-1. A time number is the number of seconds since 0:0:0.

Because date- and time 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_date/4 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_datetime(2000, 12, 3, 12, 0, 0, Num). succeeds, day- and time numbers were calculated and unified with the Num
Num = date_time(730457, 43200)
encode_datetime(1, 1, 1, 0, 1, 45, date_time(Day, Time)). succeeds, the day- and time number were unfied with the variables Day and Time:
Day = 1
Time = 105
encode_datetime(1, 1, 1, 0, 1, 45, date_time(Day, 106)). fails because the value of the time parameter is not equal to the correct time number, which is 105

 

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