Hello,

Looking for a Julian Date Converter....and ideas

This is an explanation of something I saw on the Forge of the outdated JulianDateConverter.

A Julian Date in systems like JD Edwards work this way: The first 3 digits are the year and century, starting at 1900. The second 3 digits are the day of the year. For example, 108034 would be 2008/02/03 (3 Feb 2008).  Or more current 120141 would be 2020/02/03.


As always, many thanks.

FrankCLT

Solution

Hi Frank,

There are a couple of built-in Functions you can use for this. They're hidden under the "Date and Time" folder when you have the Expression Editor opened:

Use the Year() Function to get the year, and subtract 1900 from that to get the first part of the Julian date. Next, to get the day of the year, use DiffDays with as dt1 the 1st of January of the current year (use NewDate(Year(myDate), 1, 1) to get a date with that) and as dt2 your date, and use AddDays to add one to the result. So you'd get something like this:

(Year(myDate) - 1900) * 1000 + AddDays(DiffDays(NewDate(Year(myDate), 1, 1), myDate), 1)
Solution

Killian,

Thanks for the reply,  trying your suggestion, I'm creating a client action with the input of DateIn if I'm passing in 120141 should that be defined as an integer?  Not sure how that would work.

Thanks again,

FrankCLT



Hello Frank.

Kilian explained how to send Date to Julian. In: Date, Out: Integer.

Now you are trying to do the opposite now so In: Integer, Out: Date.


Apologizes,  I guess my explanation was lacking.....This is what I meant.


DateIn (Integer  = 120141)

DateOut (Date = 5/20/2020)

Please forgive my crude sample, but this is what I was attempting.......

DateOut=(Year(DateIn) - 1900) * 1000 + AddDays(DiffDays(NewDate(Year(DateIn), 1, 1), DateIn), 1)

The easiest approach is:

  1. split the number
  2. Add 1900 to the year,
  3. Add NumberOfDays-1 to January 1st.



Yes, it's just the reverse of what I wrote. Note this is all pretty standard programming, there's little OutSystems magic here.

Awesome.......that is terrific.   Would it be too much to ask if I entered 05/20/2020 to 120141?


This has been so helpful.


FrankCLT


Let me ask a different way....I can extract the century and year for 2020/05/20, having an issue with the day of year  - 5/20

Why is that an issue? Nuno showed you how to do it. You add the day of the year to 1 January of that year, minus one.

My mistake, I am trying to reverse the original question.....

You all have helped tremendously with the DateIn = 120140 and DateOut = 05/20/2020.  I am now trying to reverse the logic with DateIn = 05/20/2020 and DateOut = 120141.

It's the 141 I'm having the issue with.


But that was exactly my original post. myDate in, Julian date out.

Year and MonthDay are of type Text.


The trick is to find the day 1 of the year you are in.

I have been jumping around from Outsystems to JD Edwards development and am getting everything crossed.  I will re-evaluate the first post and go from there.


Apologies for the confusion,  very new to Outsystems and getting overwhelmed with the platform and the development methodologies. 

Well, like I said, there's very little OutSystems-specific programming here. This logic would work almost the same in C# or JavaScript or the like.

Got it to work with Julian going in and Gregorian coming out... and Gregorian going in and Julian coming out.  So, it is working both ways I needed.   Thank you both very much.....


FrankCLT

You're most welcome Frank. Don't forget to mark one of the answers as Solution, thanks!

I've received so much help from both you and Nuno,  is it possible to give more than one a solution?

Unfortunately it is not, you can only mark one as solution.