cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert Julian date (stored as Integer) to proper date/timestamp format

msinha8
Ranger

How do I convert Julian date (stored as Integer) to proper date/timestamp format?

1 REPLY 1

msinha8
Ranger

Hello Gurus,

I tried to convert the Julian date to a calendar date with below 

 

from pyspark.sql.functions import from_unixtime, unix_timestamp

# Create a DataFrame with a Julian date column
df = spark.createDataFrame([('2459603',), ('2459604',), ('2459605',), ('112001',)], ["julian_date"])

# Convert Julian date to calendar date
df = df.withColumn("calendar_date", from_unixtime(unix_timestamp("julian_date""yyyyDDD"), "yyyy-MM-dd"))
# Save the result to a new table
save(df)
 
and the result is as below :
 
msinha8_0-1679484584020.png

which is not the expected result. Any pointers on this?

Regards,

Mritunjay Sinha