0 BEGIN PGM 81801_EN MM 1 ;NC program for calculating the date and 2 ;time from the current system time. 3 ;The control has stored the current system 4 ;time in parameter Q0 in the calling program. 5 ;The value is the time in seconds that has 6 ;elapsed since 00:00 of 1/1/1970. Since 7 ;this value is in Universal Time (UTC), 8 ;you can define the time difference 9 ;between UTC and lokal time. To do so, 10 ;enter the difference in hours in the 11 ;Q50 parameter. 12 ; 13 ;The control stores the calculated values 14 ;as follows: 15 ;Q1=Year 16 ;Q2=Month 17 ;Q3=Day 18 ;Q4=Hour 19 ;Q5=Minute 20 ;Q6=Second 21 ;You can then use these values. 22 ; 23 ;Enter the difference in hours between 24 ;UTC and lokal time 25 Q50 = 1 ;TIME DIFFERENCE IN HOURS 26 ; 27 ;Do not change anything from here 28 ;Calculation of the total seconds 29 Q10 = Q0 ;Copy the system time 30 Q51 = Q50 * 3600 ;Convert the time difference to seconds 31 Q10 = Q10 + Q51 ;System time + time difference 32 ;Calculation of year 33 Q1 = 1969 ;Start year 34 LBL 10 35 Q1 = Q1 + 1 ;Calculate the next year 36 Q12 = Q1 / 4 - INT ( Q1 / 4 ) 37 FN 10: IF +Q12 NE +0 GOTO LBL 18 ;If not divisible by 4 then no leap year 38 Q12 = Q1 / 400 - INT ( Q1 / 400 ) 39 FN 9: IF +Q12 EQU +0 GOTO LBL 15 ;If divisible by 400 then leap year 40 Q12 = Q1 / 100 - INT ( Q1 / 100 ) 41 FN 9: IF +Q12 EQU +0 GOTO LBL 19 ;If divisible by 100 then no leap year 42 LBL 15 43 Q19 = 366 * 24 * 3600 ;Year-seconds 44 Q20 = 1 ;Marker: Leap year 45 Q10 = Q10 - Q19 ;System time - year 46 FN 11: IF +Q10 GT +0 GOTO LBL 10 ;If system time positive, year not found yet 47 FN 9: IF +0 EQU +0 GOTO LBL 19 ;Year found 48 ; 49 LBL 18 50 Q19 = 365 * 24 * 3600 ;Year seconds 51 Q20 = 0 ;Marker: No leap year 52 Q10 = Q10 - Q19 ;System time - year 53 FN 11: IF +Q10 GT +0 GOTO LBL 10 ;If system time positive, year not found yet 54 LBL 19 ;Year found 55 Q10 = Q10 + Q19 ;Seconds remaining at beginning of year 56 ; 57 ;Calculation of month 58 ;January 59 Q2 = 1 ;Number of month 60 Q12 = 31 ;Number of days in month 61 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 62 FN 11: IF +Q10 GT +0 GOTO LBL 22 ;If there are seconds remaining, go to February 63 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 64 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 65 ;February 66 LBL 22 67 Q2 = Q2 + 1 ;Number of month 68 Q12 = 28 + Q20 ;Number of days in month + marker leap year 69 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 70 FN 11: IF +Q10 GT +0 GOTO LBL 23 ;If there are seconds remaining, go to March 71 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at the beginning of month 72 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 73 ;March 74 LBL 23 75 Q2 = Q2 + 1 ;Number of month 76 Q12 = 31 ;Number of days in month 77 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 78 FN 11: IF +Q10 GT +0 GOTO LBL 24 ;If there are seconds remaining, go to April 79 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at the beginning of month 80 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 81 ;April 82 LBL 24 83 Q2 = Q2 + 1 ;Number of month 84 Q12 = 30 ;Number of days in month 85 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 86 FN 11: IF +Q10 GT +0 GOTO LBL 25 ;If there are seconds remaining, go to May 87 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 88 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 89 ;May 90 LBL 25 91 Q2 = Q2 + 1 ;Number of month 92 Q12 = 31 ;Number of days in month 93 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 94 FN 11: IF +Q10 GT +0 GOTO LBL 26 ;If there are seconds remaining, go to June 95 Q10 = Q10 + Q12 * 86400 ;Remaining seconds at beginning of month 96 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 97 ;June 98 LBL 26 99 Q2 = Q2 + 1 ;Number of month 100 Q12 = 30 ;Number of days in month 101 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 102 FN 11: IF +Q10 GT +0 GOTO LBL 27 ;If there are seconds remaining, go to July 103 Q10 = Q10 + Q12 * 86400 ;Remaining seconds at beginning of month 104 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 105 ;July 106 LBL 27 107 Q2 = Q2 + 1 ;Number of month 108 Q12 = 31 ;Number of days in month 109 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 110 FN 11: IF +Q10 GT +0 GOTO LBL 28 ;If there are seconds remaining, go to August 111 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 112 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 113 ;August 114 LBL 28 115 Q2 = Q2 + 1 ;Number of month 116 Q12 = 31 ;Number of days in month 117 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 118 FN 11: IF +Q10 GT +0 GOTO LBL 29 ;If there are seconds remaining, go to September 119 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 120 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 121 ;September 122 LBL 29 123 Q2 = Q2 + 1 ;Number of month 124 Q12 = 30 ;Number of days in month 125 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 126 FN 11: IF +Q10 GT +0 GOTO LBL 30 ;If there seconds remaining, go to October 127 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 128 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 129 ;October 130 LBL 30 131 Q2 = Q2 + 1 ;Number of month 132 Q12 = 31 ;Number of days in month 133 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 134 FN 11: IF +Q10 GT +0 GOTO LBL 31 ;If there are seconds remaining, go to November 135 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 136 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 137 ;November 138 LBL 31 139 Q2 = Q2 + 1 ;Number of month 140 Q12 = 30 ;Number of days in month 141 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 142 FN 11: IF +Q10 GT +0 GOTO LBL 32 ;If there are seconds remaining, go to December 143 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 144 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 145 ;December 146 LBL 32 147 Q2 = Q2 + 1 ;Number of month 148 Q12 = 31 ;Number of days in month 149 Q10 = Q10 - Q12 * 86400 ;Remaining seconds - month-seconds 150 FN 11: IF +Q10 GT +0 GOTO LBL 38 ;If there are seconds remaining, go to Error message 151 Q10 = Q10 + Q12 * 86400 ;Seconds remaining at beginning of month 152 FN 9: IF +0 EQU +0 GOTO LBL 39 ;Go to calculation of day 153 ;Output error message 154 LBL 38 155 FN 14: ERROR= 1088 ;Data contradictory 156 ;Calculation of day 157 LBL 39 158 Q3 = INT ( Q10 / 86400 ) + 1 ;Determine the day 159 Q10 = Q10 - ( ( Q3 - 1 ) * 86400 ) ;Calculation seconds remaining 160 ;Calculation of hours 161 Q4 = INT ( Q10 / 3600 ) ;Determine the hours 162 Q10 = Q10 - ( Q4 * 3600 ) ;Calculation of seconds remaining 163 ;Calculation of minutes 164 Q5 = INT ( Q10 / 60 ) ;Determine the minutes 165 Q10 = Q10 - ( Q5 * 60 ) ;Determine the seconds remaining 166 ;Calculation of seconds 167 Q6 = INT Q10 ;Determine the seconds 168 ;End of program 169 END PGM 81801_EN MM