Forums › ProRealTime English forum › ProBuilder support › Tomorrow's date › Reply To: Tomorrow's date
OpenDayOfWeek returns:
1=Monday, … 5=Friday, so if any OpenDayOfWeek is within the range 1-5 it’s a business day (unless there’s some local holiday), so you can detect how many business days there are in each month by tallying from day 1 to the last day and skipping those ourside that range.
Anyway, I attach 4 functions (they are actually indicators, but the behaviour is the same as in other languages, they may require parameters as their input and return some data):
- DayMax (input: Month,Year returns: MaxDay)
- IsLeapYear (input: Year returns: 1=leap year, 0=no leap year)
- UnpackDate (input: Date formatted as YYYYMMDD, as PRT does returns: Day,Month,Year)
- GetDayOfWeek (input: Date formatted as YYYYMMDD, as PRT does returns: 0=Sunday,1=Monday,….,6=Saturday)
I attach both .ITF files to be imported into ProBuilder as well as .TXT files:
|
1 2 3 4 5 6 7 8 9 10 11 12 |
//input: MONTH,YEAR //requires indicator ISLEAPYEAR // MaxDay = 31 If MyMonth = 4 or MyMonth = 6 or MyMonth = 9 or MyMonth = 11 Then MaxDay = 30 Endif If MyMonth = 2 then x = CALL "IsLeapYear"[MyYear] MaxDay = 28 + x Endif RETURN MaxDay |
|
1 2 3 4 5 6 7 8 9 10 11 12 |
//input: YEAR LeapYear = 0 If MyYear mod 4 = 0 then If MyYear mod 100 = 0 then If MyYear mod 400 = 0 then LeapYear = 1 Endif Else LeapYear = 1 Endif Endif RETURN LeapYear |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//input: DATE d = 0 m = 0 y = 0 // example: x = MyDate //x = 20190326 w = round((x / 100) - 0.5) //w = 201903.00 z = w * 100 //z = 20190300 d = x - z //d = 26 // y = round((w / 100) - 0.5) //z = 2019.0000 m = w - (y * 100) //m = 3 // RETURN d,m,y |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
//input: DATE //requires indicators UNPACKDATE and ISLEAPYEAR // // https://www.wikihow.it/Calcolare-il-Giorno-della-Settimana (method 1) // MyDay, MyMonth, MyYear = CALL "UnpackDate"[MyDate] IF MyMonth = 1 OR MyMonth = 10 THEN Mvalue = 0 ELSIF MyMonth = 4 OR MyMonth = 7 THEN Mvalue = 6 ELSIF MyMonth = 9 OR MyMonth = 12 THEN Mvalue = 5 ELSIF MyMonth = 5 THEN Mvalue = 1 ELSIF MyMonth = 6 THEN Mvalue = 4 ELSIF MyMonth = 8 THEN Mvalue = 2 ENDIF d = MyDay + Mvalue WHILE d > 6 d = d - 7 WEND y = MyYear MOD 100 Century = MyYear - y Century = (Century MOD 400) / 100 IF Century = 1 THEN Century = 5 ELSIF Century = 2 THEN Century = 3 ELSIF Century = 3 THEN Century = 1 ENDIF z = y WHILE y > 27 y = y - 28 WEND y = y + round((z / 4) - 0.5) + Century IF MyMonth < 3 THEN x = CALL "IsLeapYear"[MyYear] y = y - x ENDIF d = d + y WHILE d > 6 d = d - 7 WEND IF d = 0 THEN d = 7 ENDIF RETURN d - 1 //0=Sunday, 1=Monday...... 6=Saturday |
Edit: The above GetDayOfWeek function does not work fine, it has been replaced by a new version (see post https://www.prorealcode.com/topic/tomorrows-date/page/2/#post-95272)