IJmert
21-Feb-2017, 08:13 AM
In addendum to the global date and time functions.
There is a new function that calculates the week number of a given date.
There is no function that returns the first day in a given week. I wrote this function, maybe you can add it to the package.....
Function DateGetFirstDayOfWeek Global Integer iYear Integer iWeek Returns Date
DateTime dtFirstDay
Date dFirstDay
Integer iDay
If (iWeek = 0 or iYear = 0) Function_Return 0
// 4th of Januari is always first week of year
Move (DateSetDay (dtFirstDay,4)) to dtFirstDay
Move (DateSetMonth (dtFirstDay,1)) to dtFirstDay
Move (DateSetYear (dtFirstDay,iYear)) to dtFirstDay
Move (DateGetDayofWeekISO (dtFirstDay)) to iDay // 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday, 7=Sunday
Move (DateAddDay (dtFirstDay, (-1 * iDay + 1))) to dtFirstDay
Move dtFirstDay to dFirstDay
Move (dFirstDay + ((iWeek -1) * 7)) to dFirstDay
Function_Return dFirstDay
End_Function
There is a new function that calculates the week number of a given date.
There is no function that returns the first day in a given week. I wrote this function, maybe you can add it to the package.....
Function DateGetFirstDayOfWeek Global Integer iYear Integer iWeek Returns Date
DateTime dtFirstDay
Date dFirstDay
Integer iDay
If (iWeek = 0 or iYear = 0) Function_Return 0
// 4th of Januari is always first week of year
Move (DateSetDay (dtFirstDay,4)) to dtFirstDay
Move (DateSetMonth (dtFirstDay,1)) to dtFirstDay
Move (DateSetYear (dtFirstDay,iYear)) to dtFirstDay
Move (DateGetDayofWeekISO (dtFirstDay)) to iDay // 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday, 7=Sunday
Move (DateAddDay (dtFirstDay, (-1 * iDay + 1))) to dtFirstDay
Move dtFirstDay to dFirstDay
Move (dFirstDay + ((iWeek -1) * 7)) to dFirstDay
Function_Return dFirstDay
End_Function