Convert the date and time numbers back to Year, Month, Day and Hour, Minutes and Seconds values. 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 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_date/4 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_datetime(date_time(730485, 2), Y, M, D, H, Mi, S). | 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 The time number is 2, the decoded time is: H = 0 Mi = 0 S = 2 |
| decode_datetime(date_time(1, 7678), Y, M, D, H, Mi, S). | succeeds, the values of the variables is: Y = 1 M = 1 D = 1 H = 2 Mi = 7 S = 58 |
| decode_datetime(date_time(1, 7678), Y, M, D, H, M, S). | fails, because the date number is decoded and the variables Y, M, and D are unified with values. The variable M which now contains the number of months is also used for the 'Minutes' parameter for the decoded time and these values are not equal |
| Exceptions | |
| The DateNumber and/or TimeNumber 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 |