start_of_week(+Year, +WeekNumber, ?DateNumber)

Calculate the date number for a specified week of a year, the two input parameters are the year and a week number, output is the date number of the SUNDAY of the week. The predicate day_of_week/2 also works with date numbers.

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 reverse_day_number/4

Example
start_of_week(1998, 1, DateNum). succeeds, DateNum = 729386
start_of_week(1998, 2, DateNum), decode_date(DateNum, Year, Month, Day). Succeeds and the calculated date of the sunday of week 2 of 1998 is 4 January 1998
DateNum = 729393
Year = 1998
Month = 1
Day = 4
start_of_week(1999, 20, DateNum), decode_date(DateNum, Year, Month, Day). Succeeds and the calculated date of the sunday of week 20 of 1999 is 16 May 1999
DateNum = 729890
Year = 1999
Month = 5
Day = 16

 

Exceptions  
The Year and/or WeekNumber parameters are not integers a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect argument
The DateNumber parameter is an integer nor a variable a type_error(evaluable, Value) exception is thrown, Value is unified with the incorrect argument

 

 

info@trinc-prolog.com