FormatDateTime (date/time formatting)
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
| Name | Type | Description |
|---|---|---|
format | string | A template string containing any combination of the tokens below. All other characters are passed through unchanged. |
date | Date or any | Optional. The date and time to format. Defaults to the current moment when omitted. |
Tokens
| Token | Replaced with | Example |
|---|---|---|
YYYY | 4-digit year | 2026 |
MM | 2-digit month (zero-padded) | 04 |
DD | 2-digit day of month (zero-padded) | 07 |
HH | 2-digit hour in 24-hour format (zero-padded) | 09 |
mm | 2-digit minute (zero-padded) | 05 |
ss | 2-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
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.zipFormat a timestamp from a file stat
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
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:05NOTE
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.
