Date & Time

DWScript represents points in time using the TDateTime type. Internally, this is a floating-point number where the integer part is the day and the fractional part is the time.

Retrieving Time

Use Now for local time and UTCDateTime for UTC. For interoperability with other systems, UnixTime is also available.

var dt := EncodeDate(2026, 1, 12) + EncodeTime(12, 0, 0, 0);
PrintLn('Date: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', dt));

var unix := DateTimeToUnixTime(dt);
PrintLn('Unix Time: ' + IntToStr(unix));
Result
Date: 2026-01-12 12:00:00
Unix Time: 1768219200

Formatting Dates

The FormatDateTime function provides flexible formatting using standard patterns.

var dt := EncodeDate(2026, 1, 12) + EncodeTime(12, 0, 0, 0);

// ISO 8601-like
PrintLn(FormatDateTime('yyyy-mm-dd hh:nn:ss', dt));

// Custom
PrintLn(FormatDateTime('dddd, mmmm d, yyyy', dt));
Result
2026-01-12 12:00:00
Monday, January 12, 2026

Date Arithmetic

Since dates are floats, you can add or subtract days directly. Use IncDay, IncMonth, etc., for more complex adjustments.

var today := EncodeDate(2026, 1, 12) + EncodeTime(12, 0, 0, 0);
var nextWeek := IncDay(today, 7);

PrintLn('Next Week: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', nextWeek));
Result
Next Week: 2026-01-19 12:00:00

Related Reference

For a complete list of all date manipulation functions and encoding options, see the reference documentation:

On this page