Converting the Date to Julian Date Format in Dataweave 2.0 (Mule 4)
The article explains how to change the date using the Dataweave 2.0 code to convert the Date Format ("yyyy-MM-dd") to Julian Date Format.
Join the DZone community and get the full member experience.
Join For FreeHow to Change the Date
Datawave 2.0 Code:
xxxxxxxxxx
%dw 2.0
output application/json
import * from dw::core::Strings
fun year(date) = (date as Date).year
fun dayOfyear(date) = (date as Date).dayOfYear
fun C_value(date)= floor ((year(date) - (1900))/100)
fun JulianDate(date) = C_value(date) ++ (year(date) as String) [2 to 3] ++ leftPad(dayOfyear(date),3,"0")
---
{
JulianDate: JulianDate(<Provide some Date>)
}
When the current date is provided:
x
Input:
now()
Output:
{
"JulianDate": "121018"
}
When some manual date is provided:
x
Input:
{
"Date": "2021-01-18"
}
Output:
{
"JulianDate": "121018"
}
When provided with the datetime:
x
Input:
{
"Date": "2021-01-18T19:14:31.566+05:30"
}
Output:
{
"JulianDate": "121018"
}
Published at DZone with permission of Abhishek Bathwal. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments