Julian date Studio 5000

Cajmccormick

Member
Join Date
Aug 2018
Location
Ontario
Posts
12
Hey guys,

I am currently trying to create code to display a 5 digit Julian date, taken from the current local time of the PLC. Ive searched the forum and others alike but to no avail. If anyone has any example code for 5000 or could point me in the right direction id really appreciate it!

Thanks,
Christian
 
Welcome to the PLCTalk forum community !

There is a structured text routine to calculate the Julian day in the Rockwell Sample Code website. Just search on the term "Julian" and it should pop up.
 
Welcome to the PLCTalk forum community !

There is a structured text routine to calculate the Julian day in the Rockwell Sample Code website. Just search on the term "Julian" and it should pop up.

Wow thanks a bunch! Helped quick, i never thought of using structured text.. Although, would you have an idea of deciphering todays julian "day" from the date using logic? Todays julian day is 213 but the date is 2458332.
 
OK, you just want the Julian Day, aka the Day of the Year.

For that you just use a table and brute-force it to account for the number of days per month, and 28 or 29 days for February in leap years.


To remind myself of the correct number of days I rely on NASA instead of kindergarten mnemonics:

https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html

Here's a little Structured Text routine that will calculate the Day of the Year:


// For use elsewhere in the program, there is a User Defined Datatype of "WCT" made up of 7 DINTs
// With the element names Year, Month, Day, Hour, Minute, Second, ms

GSV(WallClockTime,,LocalDateTime,WCT.Year) ; // Gets the current Wall Clock Time from the system clock.

Leap_Year_Remainder := WCT.Year MOD 4 ; // Leap Years are evenly divisible by 4, so the remainder will be 0 in a Leap Year

Case WCT.Month Of
1: Day_Value_temp := WCT.Day ;
2: Day_Value_temp := WCT.Day + 31 ;
3: Day_Value_temp := WCT.Day + 59 ;
4: Day_Value_temp := WCT.Day + 90 ;
5: Day_Value_temp := WCT.Day + 120 ;
6: Day_Value_temp := WCT.Day + 151 ;
7: Day_Value_temp := WCT.Day + 181 ;
8: Day_Value_temp := WCT.Day + 212 ;
9: Day_Value_temp := WCT.Day + 243 ;
10: Day_Value_temp := WCT.Day + 273 ;
11: Day_Value_temp := WCT.Day + 304 ;
12: Day_Value_temp := WCT.Day + 334 ;
Else Day_Value_temp := 0; // If somehow the WCT Month is not 1-12
End_Case;

If (Leap_Year_Remainder = 0) Then // If this is a leap year then we add 1 in all months that are not January or February
If WCT.Month > 2 Then
Julian_Day := Day_Value_temp + 1;
Else
Julian_Day := Day_Value_temp ;
End_If;
Else
Julian_Day := Day_Value_temp ; // If this is not a leap year then the date is correct without adjustment
End_If ;
 
I had written an AOI for it a while back.

Here is a rung you can import and, hopefully, pop in all the datatypes and AOIs.

And if it doesn't, I'll always think it should have... ;)
 
OK, you just want the Julian Day, aka the Day of the Year.

For that you just use a table and brute-force it to account for the number of days per month, and 28 or 29 days for February in leap years.


To remind myself of the correct number of days I rely on NASA instead of kindergarten mnemonics:

https://landweb.modaps.eosdis.nasa.gov/browse/calendar.html

Here's a little Structured Text routine that will calculate the Day of the Year:


// For use elsewhere in the program, there is a User Defined Datatype of "WCT" made up of 7 DINTs
// With the element names Year, Month, Day, Hour, Minute, Second, ms

GSV(WallClockTime,,LocalDateTime,WCT.Year) ; // Gets the current Wall Clock Time from the system clock.

Leap_Year_Remainder := WCT.Year MOD 4 ; // Leap Years are evenly divisible by 4, so the remainder will be 0 in a Leap Year

Case WCT.Month Of
1: Day_Value_temp := WCT.Day ;
2: Day_Value_temp := WCT.Day + 31 ;
3: Day_Value_temp := WCT.Day + 59 ;
4: Day_Value_temp := WCT.Day + 90 ;
5: Day_Value_temp := WCT.Day + 120 ;
6: Day_Value_temp := WCT.Day + 151 ;
7: Day_Value_temp := WCT.Day + 181 ;
8: Day_Value_temp := WCT.Day + 212 ;
9: Day_Value_temp := WCT.Day + 243 ;
10: Day_Value_temp := WCT.Day + 273 ;
11: Day_Value_temp := WCT.Day + 304 ;
12: Day_Value_temp := WCT.Day + 334 ;
Else Day_Value_temp := 0; // If somehow the WCT Month is not 1-12
End_Case;

If (Leap_Year_Remainder = 0) Then // If this is a leap year then we add 1 in all months that are not January or February
If WCT.Month > 2 Then
Julian_Day := Day_Value_temp + 1;
Else
Julian_Day := Day_Value_temp ;
End_If;
Else
Julian_Day := Day_Value_temp ; // If this is not a leap year then the date is correct without adjustment
End_If ;


Thanks a bunch! Saved a lot of time!
Cheers
Christian
 
2100 is not going to be a leap year. For those that can remember that far back, 1900 wasn't either. #datetime #areworsethan #nonSIunits

But 3000 will be a leap year, as 2000 was, so plan accordingly for that year. Don't want to get your 19th wife mad at you for planning something March 1, 3000 and being a day early.
 
I have been using your Julian AOI. Thanks for that. There is a bug that my operators just pointed out to me. Line 0, deltaMonth[11] is currently being set to 204, but it should be 304. Right now the calculator runs 100 days behind in the month of November.
At the moment I don't want to take the PLC offline to fix the AOI, so I am running a check right after it executes so if month==11 then it just adds 100 to your AOI output.


Thanks again for posting that for people to use.
 
Necro-thread alert

But 3000 will be a leap year, as 2000 was,


Oh dear. Every divisible-by-four year is a leap year, the exception to that is every 100th year is not (e.g. 2100, 3000), and the exception to the 100-exception is that every 400th year is (e.g. 2000). E.g.
Untitled.png
The divisible-by-four gets us from 365 to 365.25; the 100 negative exception gets us from there to 365.24 (-0.01 = -1/100); the 400 positive exception gets us from there to 365.2425 (0.0025 = 1/400).

From naif.jpl.nasa.gov:

>>> import spiceypy as sp
>>> sp.etcal(sp.tparse("3000 feb 28 12:00:00",99)[0]+sp.spd())
'3000 MAR 01 12:00:00.000'
>>> sp.etcal(sp.tparse("2800 feb 28 12:00:00",99)[0]+sp.spd())
'2800 FEB 29 12:00:00.000'
>>> sp.etcal(sp.tparse("3200 feb 28 12:00:00",99)[0]+sp.spd())
'3200 FEB 29 12:00:00.000'


Not than any of us will care, but it would be funny to see the look on someone's face when they pull out a ThinkPad running XP and ask where the cable is to connect to the SLC 5/xx that is supporting the universe 9.8 centuries from now.
 
perhaps it won't matter won't they be using startrek date system, it might be loosley based on the julian date, it is fictional though as it is impossible to convert them into current date/time.:)
 
Julian Calendar
Something to think about
I see a lot of things about it bandied around here, but I would ask all of you please take the time to actually look it up on the internet to help you understand it. I have run into this before but I actually took the time to look it up and have found at least 5 different Julian Calendars and I know there are many more. It is a fascinating read the original and most referred to starts with year zero at 47DC and counts up and down from there so a negative day it possible and would be correct. But NASA has their own version of the Julian Calendar
As do other government agencies and other originations. Microsoft has their own version for calculating they set the first 2 digits as the current year then count only days from January 1 this will have an obvious limit of just 100 years 00-99 and if think about it if the first a digits were 40 would it be 1940 or 2040 , 2140 you would have to assume a lot with that if everybody assumes the same starting point it will work but we know what they say about assuming anything.
While we all know that that’s really not practical. So to really us the Julian Calendar / Date we must first establish a common starting point / Base. If we don’t have a common base to start from it is very difficult to express the correct day. And to add to this problems each of us could establish our own Julian Calendar say starting on your birthday as day zero, wouldn’t that be a mess to work with.
When somebody refers to Julian Calendar to me, I automatically refer to the original as day zero is Jan 1 47 BC. The true Julian Time calculates to 0.25 hours.
As with all numbering systems without knowing the base and everybody using the same base / starting point numbers have little meaning by themselves they are just numbers. That’s the same with the Julian Calendar
It would be a better choice to the Naval Observatory Atomic clock as it is universally accepted and used and by most people on this planet. And it would work at least until we encounter and converse with other planets then I would expect they would have their own calendar and time base and we will have to adjust.
Please note I am not posting this to start a fight or anything but just to inspire some thought
 
Cool.

Julian day and International Atomic Time (TAI) are attempts to have a continuous value to represent time, so that arithmetic operations, such as addition, subtraction, can be applied to those time values.

The problem comes in when converting from continuous time to calendar time, because calendar time, e.g. Coordinated Universal Time (UTC) is a method of time keeping that gives a name to each instant of time of the TAI system. So the ISO format for a UTC time such as "2022-11-16T01:23:45.678" is symbolic, i.e. a name, and not numeric. It cannot be interpreted as a sequence of cascading continuous subsystems (years, months, days, hours, minutes, seconds) with rollover between them, because it is discontinuous due to leap days and leap seconds.
 

Similar Topics

using directlogic on a dl 06 I need to do calculations based on date numbers. Could someone tell me how to get a Julian date number.
Replies
3
Views
2,978
Hi, my name is Marshall. Long time browser, first time poster! I am looking for an elegant solution to a julian date problem. We have a label...
Replies
18
Views
18,192
Hi Guys, I trying to see if anyone has been able to get the Julian Date logic for the SLC family. I have found this thread ...
Replies
2
Views
5,500
In my plant, all production requires a Julian date code. I am looking for logic that converts the built in calandar in a Julian date for data...
Replies
7
Views
10,753
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.
Replies
7
Views
10,075
Back
Top Bottom