Skip to content
  • There are no suggestions because the search field is empty.

Add DateTime or Timestamp

Reference on working with datetimes and timestamps

Why:

The built-in {{System.Internal.DateTime}} evaluates in ISO8601 format which has characters that may not be desired or not be supported for filename use by the host operating system (e.g. ':' not supported in filenames on Windows OS)

Results in:

Example 1: Assign a unix timestamp in the Write Stage

The handlebar syntax can be added to the File Name directly by converting the System.Internal.DateTime to unix timestamp.

FileName{{System.Internal.DateTime.getTime()}}

Example 2: Assign an ISO8601 format using event.metadata

Example file output:
 
 
Use a pipeline to populate the metadata with the desired date format:
 
 
Transform - "SetMetadataDateTime"
//assign the built-in system date object
const date = System.Internal.DateTime;

//call method for the ISO string
const filenameSafeDateTimeISO = date.toISOString().replace(/[:.-]/g, "_");

//call method for the Unix timestamp value
const filenameSafeDateTimeUnix = date.getTime();

//assign values to metadata
stage.setMetadata("dt_iso",filenameSafeDateTimeISO); 
stage.setMetadata("dt_unix",filenameSafeDateTimeUnix);
Write New - "WriteToFile"
 

Example 3: Outputting year/month/day/hour using event.metadata

Example output

Use a pipeline to populate the metadata with the desired date format:

Transform - set event.metadata

//assign the built-in system date object
const date = System.Internal.DateTime;
//you can also use the following:
//const date = new Date();

// Extract parts, in UTC
const year = date.getUTCFullYear();
const month = String(date.getUTCMonth() + 1).padStart(2, '0'); // months are 0-based
const day = String(date.getUTCDate()).padStart(2, '0');
const hour = String(date.getUTCHours()).padStart(2, '0');

const formatted = `${year}/${month}/${day}/${hour}`;
stage.setMetadata("dt",formatted); // 2025/08/12/10
Write New
 
 

Notes:

Using the {{System.Internal.DateTime}} in the File Name of the File Output is not supported.
 
Results in: