If you’ve ever worked with Oracle/PeopleSoft’s EnterpriseOne ERP system (also known as JD Edwards or simply JDE) you’ll quickly find that dealing with dates from the database is a bit challenging. EnterpriseOne stores all dates in the system in Julian Date format. EnterpriseOne has a lot of dates in every table.
The Julian Date in EnterpriseOne goes back to the days before EnterpriseOne was called EnterpriseOne; back when it was just JD Edwards and it ran on an AS/400 (now called an iSeries or Series i). Back then, disk space (DASD) was a premium. By storing all the dates in 6-digit Julian format, the numbers could be packed (compressed) to save table or database space. Additionally, since Julian Dates are in a fairly simple numerical form, it was easy to develop routines and functions to add, subtract, and otherwise calculate dates.
Over the years, disk space has turned into a commodity. Modern computer languages and SQL can easily deal with date calculation. But EnterpriseOne data is still in this Julian Date format. So how do we deal with it, and how do we get it converted into a normal datetime data type?
This article will cover how to create and use two SQL functions to convert Julian dates to Gregorian dates and then to convert Gregorian dates to EnterpriseOne Julian format. Many of my clients use these two functions for SQL Server Reporting Services (SSRS) Reports, and various EDI interfaces, and XML feeds. These two functions are valid on any version of JD Edwards including World, OneWorld, XE, or the latest version of EnterpriseOne. If you want to use the functions on World, or directly on an IBM Series i, you’ll need to do a bit of syntax tweaking. If you’re accessing the Series i (AS/400) from SQL Server, then this function will work perfectly for you.
EnterpriseOne Julian format
All versions of JDE use a Julian Date format as follows: CYYDDD where C = Century; YY = a 2 digit year; and DD = the 3 digit number representing the day of the year (1 through 365 or 366 days on a leap year). The Century is either a 1 or 0 depending on whether you’re using year 2000 + or if you’re using dates in the 1900’s.
For example, the Gregorian Date 01/01/2009 would be Julian Date 109001 where 1 = century 2000, 09 = the last 2 digits of the year 2009; and 001 = the first day in 2009. Similarly 12/31/2009 would be represented as 109365 where the only change is the day number being 365 to represent the last day in 2009.
Note: A value of zero(0) in JDE Julian date format represents 12/31/1899 and 01/01/1900 is the numerical value 1 in Julian format.
Converting Julian Dates to Gregorian – Date J2G( )
The first function we’re going to write is one called DateJ2G() meaning “Date Julian to Gregorian”. This function has two parameters, one parm for the Julian date you wish to convert, and one parm for the format style code, which represents the format you want your Gregorian date. The DateJ2G() function will convert the date to any standard SQL Server formatted date style. A complete list of format styles can be found at at https://msdn.microsoft.com/en-us/library/ms187928.aspx.
Here’s the code to create the function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[DateJ2G] ( @JDEDATE int, @FORMAT int ) RETURNS varchar(20) AS --Written by Bryant Avey, InterNuntius, Inc. --Provided free "As Is" with no warranties or guarantees --I just ask that you keep these comments in the function, if you use it. --The complete article describing this function can be found at: --http://internuntius.com/how-to-convert-jde-enterpriseone-julian-dates --This function takes a JDE Julian Date and returns --a varchar date in the format style you specify --To us simply pass in the JDE date and the style code --Style codes can be found at --For Example: select dbo.DateJ2G(sddgj,101) from f4211 --would return the JDE date in the format of 02/29/2008. --Select dbo.DateJ2G(108060, 1) = 02/29/08 --Select dbo.DateJ2G(109060, 107) = Mar 01, 2009 --Format codes are standard SQL 2005 Date Convert codes. --Conversion codes can be found here: http://wp.me/pBPqA-a BEGIN DECLARE @sqldate datetime set @sqldate = dateadd(day,cast((1900000 + @JDEDATE)%1000 as int)-1,(cast(( cast((1900000 + @JDEDATE)/1000 as varchar(4)) + '-01-01') as datetime))) RETURN (convert(varchar(20),@sqldate,@FORMAT)) END |
To use the DateJ2G function, just pass in a date and style format as described in the comments contained in the above code.
Converting Gregorian Dates to Julian – DateG2J( )
The next function will convert any standard formatted Gregorian date string to a JDE EnterpriseOne Julian date.
Here’s the code to create the DateG2J function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE FUNCTION [dbo].[DateG2J] (@Geogian_in datetime) RETURNS int AS --Written by Bryant Avey, InterNuntius, Inc. --Provided free "As Is" with no warranties or guarantees --I just ask that you keep these comments in the function, if you use it. --The complete article describing this function can be found at: --http://internuntius.com/how-to-convert-jde-enterpriseone-julian-dates --This function takes a varchar gregorian date and returns --a Julian JDE Date --To use simply pass in the string date --For Example: select dbo.DateG2J('02/29/2008') --would return the JDE integer date of 108060. --Date input formats are standard SQL 2005 DateTime values. --Any validly formated date string will work such as 'feb 29,2008' to get 108060. BEGIN declare @JulianDate_out INT declare @Century INT declare @YY INT declare @DayofYear INT Select @Century = case when datepart(yyyy,@Geogian_in) > 2000 then 100000 else 0 end Select @YY = CAST((SUBSTRING(CAST(DATEPART(YYYY, @Geogian_in) AS VARCHAR(4)), 3, 2)) AS INT) select @DayOfYear = datepart(dayofyear, @Geogian_in) SELECT @JulianDate_out = @Century + @YY * 1000 + @DayofYear RETURN(@JulianDate_out) END |
Stewart Johnston – Submitted this on 2013/07/10.
If you’re wanting to do it in Oracle, this convert an individual field in a query:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
TO_DATE(TO_CHAR(sdppdj +1900000),’YYYYDDD’) “Promised” This will give you today as Julian for a query: ((TO_CHAR(sysdate, ‘YYYY’)-1900)*1000)+(TO_CHAR(sysdate, ‘DDD’)) e.g. The following shows what was promised to the customer before today but hasn’t shipped yet: SELECT TO_DATE(TO_CHAR(sdppdj +1900000),’YYYYDDD’) “Promised”, TO_DATE(TO_CHAR(sdupmj +1900000),’YYYYDDD’) “Last Update”, sddoco “Order”, sddcto “Type”, shhold “Hold”, sdlitm “Item”, sdlotn “Sales Lot”, sdlttr “Last”, sdnxtr “Next”, sduorg “Qty” FROM proddta.f4211 JOIN proddta.f4201 ON (sddoco = shdoco AND sddcto = shdcto AND sdkcoo = shkcoo) WHERE sdnxtr 525 AND sdppdj < ((TO_CHAR(sysdate, 'YYYY')-1900)*1000)+(TO_CHAR(sysdate, 'DDD')) ; If you've got your Julian into Excel, try this: =DATE(1900+INT(A2/1000),1,MOD(A2,1000)) |
To use the DateG2J function just follow the examples outlined in the code above.
Conclusion
As you can see, there are only a few lines of SQL code needed to convert between Julian and Gregorian dates in JDE EnterpriseOne. I used February 29, 2008 (leap year) dates in the examples to show that the functions correctly handle leap years.
Let me know how this has worked for you.