Date Functions
Overview
This article explains how to implement date functions in your mapping files when running them in Zynk Workflow.
Namespace urn:DateFunctions
Available since Zynk Workflow 2.1.4
XSLT
Declaration
To use date functions, you need to add the namespace declaration to your XSLT file:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:DateFunctions="urn:DateFunctions"
exclude-result-prefixes="DateFunctions">
<!-- transformation -->
</xsl:stylesheet>
Functions
Below is a list of available functions within the urn:DateFunctions
namespace:
- GetDate Retrieves the current date time.
string format
- DateFormat Formats the given date time value.
string dateString
string dateString, string format
- AddDays Adds or substracts days from the given date time value.
string dateString, double days
string dateString, double days, string format
- AddMonths Adds or subtracts months from the given date time value.
string dateString, int months
string dateString, int months, string format
- AddYears Adds or subtracts years from the given date time value.
string dateString, int years
string dateString, int months, string years
Example
Input XML
<?xml version="1.0" encoding="utf-8"?>
<Company>
<Products>
<Product>
<Sku>ABC</Sku>
<Supplier>Bob</Supplier>
<Priority>2</Priority>
</Product>
<Product>
<Sku>ZXY</Sku>
<Supplier>Sam</Supplier>
<Priority>1</Priority>
</Product>
</Products>
</Company>
XSLT
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:DateFunctions="urn:DateFunctions"
exclude-result-prefixes="DateFunctions">
<xsl:output indent="yes"/>
<xsl:template match="/">
<xsl:for-each select="Company/Products/Product">
<xsl:variable name="SingleQuote">'</xsl:variable>
<xsl:comment><xsl:value-of select="concat('The product, ', $SingleQuote, Sku, $SingleQuote, ', was processed at ', DateFunctions:GetDate('dd/MM/yyyy HH:mm:ss'))"/></xsl:comment>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Output
<?xml version="1.0" encoding="utf-8"?>
<!--The product, 'ABC', was processed at 29/06/2023 10:07:20-->
<!--The product, 'ZXY', was processed at 29/06/2023 10:07:20-->