Adobe Campaign - Custom Function - Find Unix Timestamp in Seconds from Date

Adobe Campaign - Custom Function - Find Unix Timestamp in Seconds from Date


Navigate:
 
Very particular situation, but a user needed a function to convert a date to a unix timestamp in seconds, as a string. This would allow for dynamic alteration of a gif to be unique for each customer. Easy to do with JS, but not so much when you need this to be slightly different for every user in a send which may cover millions of users. Instead, a custom expression editor function would work best in this scenario as it’ll leverage SQL and be substantially higher performing. For instructions on creating and importing a custom function, I’d refer to this article by Florian Courgey: https://blog.floriancourgey.com/2018/12/replace-in-expression-of-adobe-campaign
Super simple code, just takes a date input, gets the unix timestamp and then casts as a string. NOTE: For Adobe hosted instances, this will be available immediately upon import, but will not return the string properly until the overnight restart!
<?xml version="1.0" encoding="ISO-8859-1"?> <!-- namespace, name and label are for information only --> <package namespace = "nms" name = "fco-funclist" label = "FCO SQL Additional functions" buildVersion= "6.7" buildNumber = "9359"> <entities schema="xtk:funcList"> <!-- The pair "namespace:name" is the id of the functions List. To update, use the same pair --> <funcList name="dateUnixSeconds" namespace="fco"> <!-- The groupe "name" defined the group the function belongs to --> <group name="string" label="String"> <!-- The "name" value is the function id and label. To update, use the same name --> <function name="dateUnixSeconds" type="string" args="(Input)" minArgs="1" maxArgs="1" help="Takes a Date and returns it as a unix timestamp in seconds" display="Takes a Date and returns it as a unix timestamp in seconds"> <providerPart body="CAST(UNIX_TIMESTAMP($1) AS CHAR)" provider="MySQL"/> <providerPart provider="PostgreSQL" body="CAST(ROUND(EXTRACT(EPOCH FROM $1) ) AS VARCHAR)"/> </function> </group> </funcList> </entities> </package>