Skip to content

Date and time methods

Matillion ETL offers a set of proprietary methods for use with Date and DateTime variables to ease the burden of handling the multiple formats and common calculations placed on the user. The methods are described in brief below:

Method Description
.now() A date object with a current server timestamp.
.add("",) Add a specified length of time to a timestamp.
.format("") Change the format of a timestamp.
.parse("",) Parse a piece of a timestamp according to a given pattern.

Note

To use these methods, you need a Matillion ETL variable that is defined as a DateTime type, and it must have a valid default value.

Each of the above methods can be used with DateTime variables set in Matillion ETL through the Manage Environment Variables dialog.

DateTime in Manage Job Variables

The above methods are also useful in combination, such that a created date is immediately acted upon by another method. When using a variable entitled dt, for example:

${dt.now()}
${dt.add("days", 3)}

Can be written as:

${dt.now().add("days", 3)}

Note

JavaScript expressions are only available to use as parameter values within Matillion ETL components. Any valid single JavaScript expression may be used, but it is recommended that only simple expressions are used. All variables defined in the job and/or environment should also be available to reference.

Error

When entering values into a component's parameter editor, everything enclosed within ${ } of the literal string will be evaluated immediately. This validation process does not take variables into account and may assume the value is incorrect.


.now()

.now() creates a new Date object that takes the server's time and keeps it as a timestamp. The server time is determined by the instance that Matillion ETL is running on. For example, in a Python component:

print(dt.now())

.add("", )

.add() takes a predefined DateTime and adds a specified time to it. The allowed units are:

  • seconds
  • minutes
  • hours
  • days
  • weeks
  • months
  • years

Where the integer argument then states the number of those units to add to the DateTime object. Negative integers can also be given to take time away from a DateTime. For example, for a timestamp of "yesterday":

${dt.now().add("days", -1)}

.format("")

.format() takes a timestamp and reformats it into one of two styles according to the following pattern arguments:

  • yyyy/MM/dd
  • HH:mm:ss.SSS

These patterns return a DateTime as either a date or a time. For example, to return the current date on the server:

${dt.now().format("yyyy/MM/dd")}

.parse("", "")

.parse() takes a string and converts it into a Date object. For example, the string "2016" is turned into a date object with the format "yyyy" and is stored in the dt variable:

${dt.parse("yyyy", "2016")}