We’ve all used the ADD_TO_DATETIME()
Airscript function to add any given number of the supported date/time units and returns a new dateTime obj.
What if we just want to add to a Date obj instead?
Well well well, we can build our very own UDF to take care of that, and then just call our function anywhere in Studio. Let’s get on that.
UDF
ADD_TO_DATETIME(UPDATE_DATE(NOW(), date), amount, day_month_year).date
Inputs:
- date (dataType: Date)
- amount (dataType: Number)
- day_month_year (dataType: Text)
Output
All UDFs have a single output, we can choose the dataType for:
- Output dataType: Date
Your UDF should look like
Building process
Given a date obj
{
"day": 18,
"month": 2,
"year": 2022
}
-
We’ll need to do is transform it into a DateTime obj, we’ll use the
UPDATE_DATE()
function for thatUPDATE_DATE( NOW(), date)
-
Next, we’ll want to add to that DateTime obj, using the aforementioned
ADD_TO_DATETIME()
Airscript functionADD_TO_DATETIME( DateTime, 1, "month")
-
Last, we want to obtain just the date bit of the resulting DateTime obj:
dateTimeObj.date