First thing is: what is the correct entry on a csv file for datetime that would allow it to be transformed in the dw script?
Then: what would be the correct formatting in the dw script to process that datetime value?
I've tried numerous combinations of both and nothing is working. This is my latest attempt:
%dw 2.0
input records application/csv
output application/apex
---
records map(record) -> {
-- some other fields --
TestDateTime__c: (record.DT >> "UTC") as String {format: "hh:mm:ss a, MMMM dd, uuuu"}
} as Object {class: "MyObject__c"}
I've also tried:
TestDateTime__c: record.DT as DateTime {format: "yyyy-MM-dd'T'HH:mm:ss.SSSZ"}
and many others.
But I'm just not getting the right combination of csv datetime and dw transformation.
Has anyone been able to correctly process datetime for csv -> Apex?
,
datetime handling in DataWeave with CSV can definitely be frustrating — here’s what usually works well:
CSV Format Enter the datetime like this:
2025-04-30T14:45:00Z (This format is standard and includes the date, time, and timezone.)
DataWeave Script Format:
TestDateTime__c: (record.DT as DateTime {format: "yyyy-MM-dd'T'HH:mm:ssX"}) as String
Read the DT field as a DateTime
Match it to the ISO format in the CSV
Convert it into a string for Apex
Make sure there are no extra spaces or invalid characters in the CSV column always include the time zone (Z or +00:00) in the CSV.
Avoid formats like “hh:mm a, MMM dd” — they’re harder to parse reliably.
If you find this answer helpful please mark this as an accepted answer.