Siemens S7 Julian Date Conversion Formula

Mike Graham

Member
Join Date
Jun 2005
Posts
2
I am using a Siemens S7 300 and I need the formula to convert the standard date to julian date. For example, June 1, 2005 to 05152. Thanks.
 
I just tracked back through an old program we used for generating serial numbers. We pulled the Julian date from the HMI then tacked the sequence number on the end. Ex. first piece today would be 051530001. Don't know if that would help, but that's how we did it.
 
Conversion of date

"A variable with the Data Type DATE is stored in a word as an unsigned fixed point number. The contents of the variable corresponds to the number of days since January 1, 1990."
- Hans Berger

Therefore you should be able to store a variable (or use a contant, less flexible for next year though) with the number of days up until the beginning of this year. do the subtraction and voila- julian date.
 
Julian Date Formula

I finally found the formula to calculate the julian date. Here it is. Thanks for the replies. I tried using the "Date" data type but it always has 1/1/1990 as a date. I'll have to read up on how to use that.
Mike


Find out the number of total days

days in year = 31 for JAN + 14 in FEB = 45
No. complete years * 365 = 1994 * 365 = 727810
19 centuries * 24 leap years/century = 456
1 leap year every 400 years = 19/4 = 4
leap years in current century = 94/4 = 23
Total days = 728 338
We can write a general formula as
Days = days in YY + (CCYY-1)*365 + CC*24 + TRUNC [CC/4] + TRUNC [(YY-1)/4]

where TRUNC[ ] truncates the integer divide to its lowest integral value; CC = 19; YY = 95


Next we need a method to convert total days into a calendar date.

Every 400 year interval has a constant number of days
days = 400*365 + 4*24 + 1 = 146,097 days
Within a 400 year interval every 100 year interval contains
days = 100*365 + 24 = 36,524 days
Within a 100 year interval every 4 years contains
days = 4*365 + 1 = 1,461 days
Finally within a 4 year interval each year contains 365 days.


With this information we can determine a calendar date by successively dividing out the intervals and multiplying as

Number of 400 year intervals



728,338/146,097 = 4, remainder = 143,950

4 * 400 = 1600

Number of 100 year intervals



143,950/36,524 = 3, remainder = 34,378

3 * 100 = 300

Number of 4 year intervals



34,378/1,461 = 23, remainder = 775

23 * 4 = 92

Number of 365 day years



775/365 = 2, remainder = 45

2

Accumulated years

1994


We have 1994 years plus 45 days into 1995

CCYY = 1994 + 1
MM = February
DD = 45 - 31(JAN) = 14
The calendar date is February 14, 1995.

The formula for the algorithm becomes
CCYY = TRUNC [DAYS/146,097] * 400 + TRUNC [remainder/36,524] * 100 + TRUNC [remainder/1,461] * 4 + TRUNC [remainder/365] + remainder
where the final remainder is the day number of the following year which is converted to a month and day.
 
Mike Graham said:
I finally found the formula to calculate the julian date. Here it is. Thanks for the replies. I tried using the "Date" data type but it always has 1/1/1990 as a date. I'll have to read up on how to use that.

Try using SFC1 to pull the Date & Time from the PLC, followed by (IEC) FC6 to get just the date.
 
I am assuming that you are refering to the astronomical Julian date, as some people would confuse 2005153 (Today) with a Julian date when it is not, it is just a date notation that means the 153rd day of 2005.

1/1/1990 0:00:00 is 2447892.5 JD. If you have the days since then then just add it to 2447892.5 (Note JD days change at noon not midnight, hence the .5)


Alternatevly, Jan 1 2005 0:00:00 is 2453371.5, you can create a counter to increment daily at midnight, preload it with 153 (the nubmer of days so far this year), and make Jan 1 2005 your reference, giving you 2453524.5. Then you can adjust the fraction to match the time of day and add it to the date.
 
Last edited:
Julian Date that starts at 1 each year

email me and I can send you a 9 network FC (in a library file) that will calculate the Julian Date for years after 2000.
 
Julian Date Library file

Here is the Library file. I figured out that I could attach the file. This has not been tested exhaustively. I read the explanation that was given about the Julian Date calculation and realized that would would not work with the Step 7 Date format. This because it is relative to 1990. I applied the principle that I saw in the previous explantaion and came up with a simple FC for calculating the Julian Date. Enjoy, or ignore, your choice. Good luck anyway.
 

Similar Topics

Good morning fellow sea captains and wizards, I am being asked to do the above and obtain 4 values from each slave, I know about the MRX and MWX...
Replies
21
Views
233
Hi everyone, I am an omron plc tec , lately I came across a siemens s7 200 cn plc . Can someone help me regarding the software required and...
Replies
26
Views
465
This is the first time I am working with Simatic Manager Step7 as I started my siemens journey with TIA which is pretty easy and do a lot of stuff...
Replies
3
Views
117
Hi, I have PLC S7-1200 and switch XC-208 and Iam trying to implement this SNMP library: SIOS I am not sure, what I am doing wrong, but there is...
Replies
3
Views
122
Hi all, i am the new controls guy at the plant and i have inherited a pc from the previous controls guy with Siemens tia portal version 16 and 17...
Replies
20
Views
745
Back
Top Bottom