1

I have dataframe df with column name ILDGL which record date in jde julian date format. I tried to convert that julian date into calender date and store in column ILDGL_Normal But I am not sucessful.

df = df.withColumn("ILDGL_Normal", to_date(concat(lit("20"), col("ILDGL")), "yyMMdd"))

Julian date 123002 mean 2023-01-02, 000001 mean 1900-01-01. How can i convert jde enterprise julian date into normal date format of YYYY-MM-DD?

Mohana B C
  • 5,021
  • 1
  • 9
  • 28
Arpan Ghimire
  • 183
  • 1
  • 1
  • 8

1 Answers1

0

The JDE Julian date format is CYYDDD

C - Century, Y - Year, D -Day of year

We can ignore Century and convert date to yyyy-MM-dd using to_date function. After that add years by checking centruy.

spark.conf.set("spark.sql.legacy.timeParserPolicy", "LEGACY")

df = spark.createDataFrame([('123002',), ('201002',), ('301002',)], ['jde_julian_date'])

df.withColumn("std_date",
              add_months(to_date(substring("jde_julian_date", 2, 5), 'yyDDD'),
                         when(substring("jde_julian_date", 0, 1) > 1,
                              (substring("jde_julian_date", 0, 1) - 1) * 100 * 12).
                         otherwise(0))).show()

+---------------+----------+
|jde_julian_date|  std_date|
+---------------+----------+
|         123002|2023-01-02|
|         201002|2101-01-02|
|         301002|2201-01-02|
+---------------+----------+
Mohana B C
  • 5,021
  • 1
  • 9
  • 28