AB SLC5/03 real time clock


Thread Starter


I have to do something at the same time each day but only on weekdays. The time of day is no problem but how can I determine what the weekday is.
Currently we are setting the date in a compare and looking at the system date for the trigger. This requires changing the date in the compares weekly to setup for the next week.
I can't find a day-of-week function in this PLC. Any other tricks I can use?

Jerry Hayden
Denso - Athens,Tn
Hi Jerry, I have done this really crudely using a day counter - at midnight increment counter by one so that eg Monday=1 etc then just check limits of counter acc to see if weekday ie weekends = 6,7 then reset counter after 7.
Hope this helps



Sadly, this popular function is not yet available in the 5/03. It's made it to the 5/05, the Pico, and the MicroLogix series, but in the 5/03 the Status File location (S:53 low byte) is only reserved for its future
implementation. Here's a code fragment that works well...

Cut the following string and paste it into RSLogix500:

SOR EQU S:40 0 CTU C250:0 7 0 EOR SOR XIC C250:0/DN RES C250:0 EOR SOR
LIM 1 C250:0.ACC 5 OTE B251:0/0 EOR

These three rungs will make B251/0 true only on days numbered 1-5, with 0 and 6 representing Saturday and Sunday. You will have to seed C250:0.ACC with the number of the day upon which you implement the function.

Hope this helps!

Larry Lawver
Rexel / Central Florida

Curt Wuollet

Do thay have a raw second or hour count and a modulo divide? I don't have refs here at home. Weeks are consistant, dates are sometimes not.



David Alvarez Quiroga

The procedure from Lewis is right and simple. If you have got in your application a RTC and you know date and time then you could use this algorithm for taking out day of the week and therefore launch your event only on weekdays.


Doing it this way you will have no problem when you update date. If you use Lewis procedure then remember to introduce day of the week whenever you set date and time.

Hope this helps.
The 5/03 does have a day of week (think address is shared with some little used function) that is not well documented, S:53 0 = Sunday 6 = Saturday

Yosi Feigenbaum

Hi Jerry,

Don't increment the counter at midnight, rather
increment the counter when within a time range.
For example between midnight and 12 p.m. If you increment the counter at midnight and the controller is off you'll skip a day. The above solution won't completely solve the problem but it will alleviate it somewhat.

Good Luck,

(8{)} ( .)
[email protected]
Good idea, it would save us from changing the dates in the compares each week. I'm surprised AB doesn't have a day-of-week function.

Gerald Beaudoin

S53 in the SLC 5/05 series indicates what day of the week it is. You could change the processor or develop a little routine to calulate the day of the week.

Gerald Beaudoin

Steve Myres, PE

If you're concerned about losing a day, rather than increment when within a time range, I would constantly calculate the number of days from a known starting point, like the first Sunday in Year 2000, then do a MOD 7 to get the day of the week. That approach will always work, even if the PLC has been off for a month, as long as the backup battery is good (and if that dies, you'll be reloading the program anyway). Don't forget to compensate for leap days.
The easiest and likely least expensive solution could be installing a battery backed building control lighting timer that is programmable for all seven days of the week. Set the timer to run a specific time of the day when you need to do your daily task and have the output of the timer turn on a PLC input. A good $100-$200 dollar timer might be much less expensive to install than the programming methods below. Use the PLC logic to tightly control the length of time you need to do your daily task.

A daily incremented counter will work but the accumulator must be manually set if you replace the PLC or stop scanning logic.

If you have a PC based MMI or a VB application that can communicate to your PLC you can write a simple script or simple VB code supply the day of the week to a PLC register.

If it must be PLC only solution this problem reminds me of an application where we needed to determine the Julian day of the year in a PLC5. That solution required knowing how many days in each month for a particular year. This solution could be adapted for your use.

Rules for Leap Years
1) Every year divisible by 4 is a leap year. ie: 2004 will be a leap year.
2) Except years divisible by 100 years are not. ie: 2100 will not be a leap year.
3) Except years divisible by 400 years is a leap year. ie: 2000 was a leap year

This simple solution will work for any Julian Day calculation from 1/1/1901 thru 2/28/2100. An indexed integer data table was set up adding the days for the previous months in a non leap year as follows:
N10:0=X N10:1=0, N10:2=31, N10:3=59, N10:4=90 N10:5=120, N10:6=151, N10:7=181, N10:8=212 N10:9=243, N10:10=273, N10:11=304, N10:12=334.

Expressions that needs to be converted to ladder:
[JulianDay] = N10:[Month] + [Day]

If ([Year] Mod 4 = 0 AND [Month] > 2) Then [JulianDay] = [JulianDay] + 1

For your app you need to determine how many days have passed from a specific date. To keep the calculations needed to a minimum I selected the first Monday of the year 2000 or 1/3/2000. If the PLC only has 16 bit integer math this solution is limited between the dates from 4/17/1910 thru 9/19/2089. If your PLC has 32 bit integer math and you need to go beyond the data range of 1/1/1901 thru 2/28/2100 you need to add more math to handle leap year rules 2 and 3 above. Create a data table with these values:
N20:0=X N20:1=(-3), N20:2=28, N20:3=56, N20:4=87 N20:5=117, N20:6=148, N20:7=178, N20:8=209 N20:9=240, N20:10=270, N20:11=301, N20:12=331.

For Monday=1 thru Sunday=7 here are the final expressions that need conversions to ladder:
[CurrentYearOffset] = N20:[Month] + [Day]

IF ([Year] MOD 4 = 0 AND [Month] > 2) THEN [CurrentYearOffset] = [CurrentYearOffset] + 1

[DaysOffset] = (([Year]-2000)*365)+[CurrentYearOffset]+INT(([Year]-2000)/4)
IF (([Year]-2000) MOD 4 <> 0) THEN [DaysOffset] = [DaysOffset] + 1

[DayOfWeek] = ([DaysOffset] MOD 7) + 1