real time clocks

R

Thread Starter

Ritchie

Given that a PLC has a RTC, what is the best way to calculate a future calendar date given the current date plus x-days?
 
W

William Hullsiek

The ACM (Association for Computing Machinery)
has a set of date algorithms developed by the Jet Propulsion laboratory that will convert three-coordinate date (Year, Month, Day) into a single-coordinate date (sometimes called a Julian date).

Psuedo-Code:

1. Convert (year,month,day) to jday
2. Add N days to jday
3. Convert jday to (year, month, day)

This code has been published since the early 60's. I have implemented the algorithm in Bailey Net-90 stuff, basic, c, fortran, pascal and modula-2. It is straightforward.
 
R

Ranjan Acharya

There is a guide by Claus Tonderling - just search for his Calendar FAQ via any suitable Search Engine - that you could use to help you here. You could calculate the ordinal day of the year (1 to 365 / 366) and go from there or calculate the Julian Day / Modified Julian Day and go from there. The JD and MJD are large numbers and intermediate results are large too.

That is just a starting point. There are other FAQs and help sheets on the web with lots of calendar tips.

R
 
Top