Skip to content

FormatDateTime (date/time formatting)

ts
function FormatDateTime(format: string, date?: Date | any): string;

NOTE

This function is available as of Syncplify Server! v7.1.1. If you are running an older version, upgrade to v7.1.1 or later to use it.

Formats a date and time value as a string using simple token-based placeholders. When date is omitted, the current date and time is used. date may be a native JavaScript Date object or a Go time.Time value returned by SyncJS file or VFS functions.

Parameters

NameTypeDescription
formatstringA template string containing any combination of the tokens below. All other characters are passed through unchanged.
dateDate or anyOptional. The date and time to format. Defaults to the current moment when omitted.

Tokens

TokenReplaced withExample
YYYY4-digit year2026
MM2-digit month (zero-padded)04
DD2-digit day of month (zero-padded)07
HH2-digit hour in 24-hour format (zero-padded)09
mm2-digit minute (zero-padded)05
ss2-digit second (zero-padded)30

IMPORTANT

Tokens are case-sensitive. MM is the month; mm is the minute. HH is always in 24-hour format.

Returns

The formatted date/time string.

Examples

Timestamp in a filename

ts
var stamp = FormatDateTime('YYYY-MM-DD_HH-mm-ss');
var archive = '/var/outbox/export_' + stamp + '.zip';
// e.g. /var/outbox/export_2026-04-07_09-05-30.zip

Format a timestamp from a file stat

ts
var info = StatFileSystemObject('/var/inbox/upload.csv');
var modified = FormatDateTime('YYYY-MM-DD HH:mm:ss', ToDate(info.TimeStamp));
Log('File last modified: ' + modified);

Format a JavaScript Date object

ts
var d = new Date(2026, 3, 7, 9, 5, 30); // April 7, 2026 09:05:30
Log(FormatDateTime('DD/MM/YYYY HH:mm', d));
// Output: 07/04/2026 09:05

NOTE

If you need the current date formatted as a string using only standard JavaScript, you can also use new Date() with its native methods. FormatDateTime is provided as a shortcut for the most common token-based formatting patterns used in file names and log messages.