Skip to content

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: 2.1.4

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. You can optionally specify the format you would like the date to be returned in. By default it is returned in ISO 8601 format.

Overloads

  • GetDate()
  • GetDate(string format)

DateFormat

Formats the given date time value. You can optionally specify the format you would like the date to be returned in. By default it is returned in ISO 8601 format.

Overloads

  • DateFormat(string dateString)
  • DateFormat(string dateString, string format)

AddDays

Adds the specified number of days from the given date time value. If a negative number is provided, the specified number of days will be subtracted. You can optionally specify the format you would like the date to be returned in. By default it is returned in ISO 8601 format.

Overloads

  • AddDays(string dateString, double days)
  • AddDays(string dateString, double days, string format)

AddMonths

Adds the specified number of months from the given date time value. If a negative number is provided, the specified number of months will be subtracted. You can optionally specify the format you would like the date to be returned in. By default it is returned in ISO 8601 format.

Overloads

  • AddMonths(string dateString, int months)
  • AddMonths(string dateString, int months, string format)

AddYears

Adds the specified number of years from the given date time value. If a negative number is provided, the specified number of years will be subtracted. You can optionally specify the format you would like the date to be returned in. By default it is returned in ISO 8601 format.

Overloads

  • AddYears(string dateString, int years)
  • AddYears(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-->