Reputation: 123
I want to substract one day from a date
string
in Mule using DataWeave
:
Exemple:
Input date : 18/03/2017 09:20:55
Output date : 17/03/2017 09:20:55
Upvotes: 0
Views: 4587
Reputation: 10
{ currentdateTime: (now as :localdatetime {format : "dd/MM/yyyy HH:mm:ss"})as :string {format : "dd/MM/yyyy HH:mm:ss"}, beforedate: ((currentdateTime) - |P1D|)as :string {format : "dd/MM/yyyy HH:mm:ss"} }
Upvotes: 0
Reputation: 1277
As another alternative, we can follow the example from Date Time Operations documentation for Subtracting a Period of Time. In that example we can defining the period between '|' characters. For example: |P1D|
.
Therefore, we can do the following steps to subtract one day from a date String:
"18/03/2017 09:20:55" as :localdatetime {format: "dd/MM/yyyy HH:mm:ss"}
[the Date on step #1] - |P1D|
[the subtracted Date on step #2] as :string {format: "dd/MM/yyyy HH:mm:ss"}
Upvotes: 1
Reputation: 66
%dw 1.0
%output application/json
%var aPeriod=("P" ++ 1 ++ "D") as :period
%var cDatetime= now as :datetime {format: "MM/dd/yyyy HH:mm:ss"}
---
{
previousDate: (cDatetime - aPeriod) as :datetime {format: "MM/dd/yyyy HH:mm:ss"}
}
Upvotes: 1