Date formatting in DataWeave 2.0

We often encounter scenarios to convert dates from one format to another, and I find the date formatting a massive task in itself. Date conversion becomes essential in a state of affairs where there is a need to sync two databases/systems. It's not an easy task since most databases/systems have their specific formats. Maybe the… Continue reading Date formatting in DataWeave 2.0
We often encounter scenarios to convert dates from one format to another, and I find the date formatting a massive task in itself. Date conversion becomes essential in a state of affairs where there is a need to sync two databases/systems. It’s not an easy task since most databases/systems have their specific formats. Maybe the client wants a date in some particular format; hence, the responsibility to convert from one format to another falls upon Mule or, say, falls upon us, MuleSoft developers. We’ll explore on conveniently change the date formatting in DataWeave.
Let’s start simple and understand the native date types in DataWeave Format.
- Date: Date represented in yyyy-MM-dd format. E.g: 2020-10-17
- DateTime: Conjunction of Date and time in yyyy-MM-ddTHH:mm:ss format with timezone. E.g: 2020-10-17T23:57:59+05:30
- LocalDateTime: Conjunction of Date and time in yyyy-MM-ddTHH:mm:ss format without timezone.E.g: 2020-10-17T23:57:59
- LocalTime: Time in the current timezone.E.g: 23:57:59
- Timezone: Time relative to GMT. Must start with a + or – . E.g: +05:30
- Period: Represents an amount of time in following form P[n]Y[n]M[n]DT[n]H[n]M[n]S. It consists of two parts – Date period, the part before T and Duration, the part after T
Below is the DataWeave script to check the native date types in DataWeave:
{ Date: typeOf(|2020-10-17|), DateTime: typeOf(|2020-10-17T23:57:59+05:30|), LocalDateTime: typeOf(|2020-10-17T23:57:59|), LocalTime: typeOf(|23:57:59|), TimeZone: typeOf(|+05:30|), Period: typeOf(|P1Y|) }
Below is the Output for the script above:
{ "Date": "Date", "DateTime": "DateTime", "LocalDateTime": "LocalDateTime", "LocalTime": "LocalTime", "TimeZone": "TimeZone", "Period": "Period" }
To get the current time of the system, Dataweave offers now() function.
Printing now() will output:
"2021-02-11T15:04:31.277+05:30"
The details like day, month, year etc., are facilitated by now() function.
{ "Current Date and Time": now(), "Year": now().year, "Quarter": now().quarter, "Month": now().month, "Day": now().day, "Hour": now().hour, "Minutes": now().minutes, "Seconds": now().seconds, "Day Of Week": now().dayOfWeek, "Day Of Year": now().dayOfYear }
Below is the output for the script above:
{ "Current Date and Time": "2021-02-11T09:37:14.406Z", "Year": 2021, "Quarter": 1, "Month": 2, "Day": 11, "Hour": 9, "Minutes": 37, "Seconds": 14, "Day Of Week": 4, "Day Of Year": 42 }
Formatting Dates:
DataWeave can help us attain dates in different formats than what now() returns. Please note that the below script is just an example of the different date formats and doesn’t encompass all the possible scenarios.
%dw 2.0 output application/json --- { "Current Date and Time": now(), "LocalDateTime": now() as LocalDateTime, "Date in dd-MM-yyyy format": now() as Date {format: "dd-MM-yyyy"}, "Date in dd-MMM-yyyy format": now() as Date {format: "dd-MMM-yyyy"}, "Date in dd/MM/yyyy format": now() as Date {format: "dd/MM/yyyy"}, "Date in dd/MMM/yyyy format": now() as Date {format: "dd/MMM/yyyy"}, "Date in dd E, MMM, yyyy format": now() as Date {format: "dd E, MMM, yyyy"}, "Date in yyyy/MMM/dd format": now() as Date {format: "yyyy/MMM/dd"}, "Date in dd/MMM/yyyy format": now() as Date {format: "dd/MMM/yyyy"}, //Instead of HH and hh, kk and KK can be used respectively "Date in 24hr Format" : now() as String {format : "dd-MM-yyyy HH:mm:ss"}, "Date in 12hr Format" : now() as String {format : "dd-MM-yyyy hh:mm:ss a"} }
Output:
{ "Current Date and Time": "2021-02-11T09:38:40.959Z", "LocalDateTime": "2021-02-11T09:38:40.959", "Date in dd-MM-yyyy format": "11-02-2021", "Date in dd-MMM-yyyy format": "11-Feb-2021", "Date in dd/MM/yyyy format": "11/02/2021", "Date in dd/MMM/yyyy format": "11/Feb/2021", "Date in dd E, MMM, yyyy format": "11 Thu, Feb, 2021", "Date in yyyy/MMM/dd format": "2021/Feb/11", "Date in dd/MMM/yyyy format": "11/Feb/2021", "Date in 24hr Format": "11-02-2021 09:38:40", "Date in 12hr Format": "11-02-2021 09:38:40 AM" }
Here, we saw a few examples of formatting system dates and dates received as part of payload into different formats and how to extract information from dates.
*There can be many more scenarios for date conversions other than the one in this MuleSoft technical guide.
Recent Blogs

Connecting MuleSoft and Azure SQL with Entra ID
Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID
Connecting MuleSoft and Azure SQL with Entra ID
Introduction Establishing a secure connection between MuleSoft and Azure SQL Database can be challenging, especially if you are using Entra ID (formerly known as Azure Active Directory) for authentication. This blog walks through a fully working configuration for connecting to Azure SQL using ActiveDirectoryServicePrincipal in Mule runtime 4.7.4 with Java 8 — addressing driver setup,… Continue reading Connecting MuleSoft and Azure SQL with Entra ID

Understanding Salesforce Flow Approval Processes
Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes
Understanding Salesforce Flow Approval Processes
Introduction: Salesforce introduced Flow Approval Processes in the Spring '25 release. This is an evolved version of the classic approval process model, powered by Flow Orchestrator. The new approach brings unprecedented flexibility, enabling the creation of dynamic, multi-level, and logic-driven approval workflows that are entirely declarative. Continue reading the blog to get a deeper understanding… Continue reading Understanding Salesforce Flow Approval Processes

Capturing Real-time Record Updation Using LWC
Introduction In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a… Continue reading Capturing Real-time Record Updation Using LWC
Capturing Real-time Record Updation Using LWC
Introduction In modern CRM ecosystems, real-time Salesforce integration and seamless user experiences are no longer optional but fundamental for driving operational efficiency. Imagine your sales reps making important Opportunity changes, but the ERP remains out of sync, leading to confusion and data errors. We understood the necessity to bridge this data gap and implemented a… Continue reading Capturing Real-time Record Updation Using LWC

All About Schedulers: Mule 4
In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4
All About Schedulers: Mule 4
In the world of Mule 4, automating repetitive tasks and triggering flows at defined intervals is necessary for building efficient and robust integration solutions. This is where Mule 4 schedulers come into use. This blog post explores the intricacies of scheduling in Mule 4, providing practical examples and best practices to help you get deeper… Continue reading All About Schedulers: Mule 4