devxlogo

Converting Julian Dates to Gregorian Dates

Converting Julian Dates to Gregorian Dates

Question:
How do I change a Julian date to a Gregorian date and remain Y2K compliant?

Answer:
I am not sure how the year is stored in the Julian date, so I will suppose that it is at the beginning of the Julian string for the sake of this solution. I will also assume that the Julian date is stored as a character value.

Let’s assume there is a Julian date 1999003, which would be Jan 3, 1999. Create a PRG file with the following code in it:

?ConvertJulianToDate("1999003") PROCEDURE ConvertJulianToDateLPARAMETERS tcJulianDateLOCAL lcJulianYear,lcJulianNumberLOCAL lnJulianNumber, ldReturnValuelcJulianYear = LEFTC(tcJulianDate,4)lcJulianDay  = RIGHTC(tcJulianDate,3)lnJulianDay  = VAL(lcJulianDay)*-- Create a date that is Jan 1st of Julian yearldReturnValue = CTOD("01/01/"+lcJulianYear)*-- Add the numeric Julian date and subtract*-- one because Jan 1 = 1, not zeroldReturnValue = ldReturnValue + lnJulianDay - 1RETURN ldReturnValueENDPROC

See also  How College Students Can Shape the Future of Tech Responsibility
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist