Calculate the date since January 1. 1984

Michal_dk

Member
Join Date
Oct 2007
Location
Vejen
Posts
153
Hi!

I'm trying to find the most accurate way of calculating todays date, based on the number of days elapsed since January first 1984.
Apparently this is a "normal" way of displaying the date in CPUs, but I have not been able to find anything about it (google has not been my friend in this).
All I get is links to calculators or how to use a function in Excel.
I'm using a Siemens S7-1200 CPU at the moment, but we will be using this in a multitude of PLC brands.

When I read the days counter I get 8401 days since 1984-01-01 (the date in my drive is 2007-01-01). 8401/365 = 23,01643835..... 1984 + 23 = 2007 - but I'm concerned about leap years and february medling with my numbers.

I'm sure i have seen this calculation somewhere before, but i can't remember where :-(
 
Edit: Nevermind.. I misunderstood.

[Can't you calculate with average number of days/year until current year?
A year has 365.2422 days.]
 
Last edited:
I've never heard of this as a "normal" thing, using 1984 as the beginning of time. Unix time starts in 1970, and that is used for the DTL data type in the S7-1200s. The DATE and DATE_AND_TIME data types both start in 1990.

If you just want the current Date/Time from the PLC, you can read it with the RD_LOC_T instruction, under Instructions -> Extended instructions -> Date and time of day.

Is there a specific reason you need to start counting in 1984? Realistically, this is something that may be easier to make platform dependent.

Time calculations are tricky, although it's easier if you're only doing date and not time. If you want to calculate this accurately, you might want to peek at the OSCAT library code, as an example. I don't think they have blocks for the 1200, but you may be able to get the sources for one of the formats.
 
I guess I was wasn't clear on what i'm trying to do.

Yes I can read the time from a PLC and find the date and time of the PLC, but this date and time is in my drive and I need to read and write it to ensure that the PLC/SCADA time is syncronised to the drive.

The reason for 1984 is apparently Profibus, at least that is what I'm being told. I haven't dived into that, as I have no way of changing it.

The read function should be the same on all platforms, as it is essentially the same drive (just different fieldbusses). But the write function is going to be specific to each PLC brand in question, as they will most likely have different representations of Date and Time.

I found the needed help on this page:

http://howardhinnant.github.io/date_algorithms.html#civil_from_days

Although it is in C, I have at least managed to read the drive date using SCL code in the S7-1200 (a first for me). Next bit will be to calculate the other way round, but that is also described in the document.
 
I was given this task 20 years ago in high school as punishment for writing what was essentially a password stealing bit of code and installing it on all the school computers.

Computer science teacher told me i was banned from class until I'd written this to tell him number of seconds since 1/1/1984.

I stayed up all night figuring it out and writing the application in Pascal. Teacher was a bit annoyed I'd gotten it so easily. This was before we had Google.

Reckon I'd be banned for a week now. I remember having to account for leap years but i can't remember much else!
 

Similar Topics

Hi everyone, This is my first time posting, so please forgive any omissions or mistakes. I am attempting to control the velocity of a stepper...
Replies
18
Views
1,053
Good morning, I have a question. I don't know much about ST yet I would like to calculate the average number of products per hour. how do I do...
Replies
22
Views
2,977
Can someone help me with this? I'm no good at SCL - virtually everything I've done so far has been ladder logic. The return value from the...
Replies
13
Views
1,117
I want to calculate the energy consumed from instantaneous power. Can this be done using the TOT block with timebase set to Hour?
Replies
2
Views
699
Hi everyone, I have to calculate the length in millimeters of a glass that enters a transport (I don't know the speed yet) through a barrier...
Replies
15
Views
3,471
Back
Top Bottom