Converting Date to Julian Date Format in dataweave 1.0 (Mule 3)

Author: Abhishek Bathwal

The Blog contains the Dataweave 1.0 code for converting the Date format (“yyyy-MM-dd) to Julian Date format.

Datawave 1.0 Code:

%dw 1.0
%output application/json
%function year(date) (date as :date).year
%function dayOfyear(date) (date as :date).dayOfYear
%function C_value(date) floor ((year(date) – (1900))/100)
%function JulianDate(date) (C_value(date) as :string {format: ‘#’}) ++ (year(date) as :string) [2..3] ++ dayOfyear(date)

{
JulianDate: JulianDate(<Provide some Date>)
}

When Current Date is Provided:

%dw 1.0
%output application/json
%function year(date) (date as :date).year
%function dayOfyear(date) (date as :date).dayOfYear
%function C_value(date) floor ((year(date) – (1900))/100)
%function JulianDate(date) (C_value(date) as :string {format: ‘#’}) ++ (year(date) as :string) [2..3] ++ dayOfyear(date)

{
JulianDate: JulianDate(now)
}

Output:

{  
“JulianDate”: “120322”
}

When Some Manual Date is Provided:

%dw 1.0
%output application/json
%function year(date) (date as :date).year
%function dayOfyear(date) (date as :date).dayOfYear
%function C_value(date) floor ((year(date) – (1900))/100)
%function JulianDate(date) (C_value(date) as :string {format: ‘#’}) ++ (year(date) as :string) [2..3] ++ dayOfyear(date)

{
JulianDate: JulianDate(“2020-11-19”)
}

Output:

{  
“JulianDate”: “120324”
}

When Provided with DateTime:

%dw 1.0
%output application/json
%function year(date) (date as :date).year
%function dayOfyear(date) (date as :date).dayOfYear
%function C_value(date) floor ((year(date) – (1900))/100)
%function JulianDate(date) (C_value(date) as :string {format: ‘#’}) ++ (year(date) as :string) [2..3] ++ dayOfyear(date)

{
JulianDate: JulianDate(“2020-11-20T13:54:02.011+05:30”)
}

Output:


 “JulianDate”: “120325”
}

We use cookies on this site to enhance your user experience. For a complete overview of how we use cookies, please see our privacy policy.