Handling dates and times in DWScript is centered around the TDateTime type, which is technically a Float where the integer part represents days since Dec 30, 1899, and the fractional part represents the time of day.
| Function | Parameters | Description |
|---|---|---|
Now |
|
Current local date and time. |
Date |
|
Current local date only. |
Time |
|
Current local time only. |
UTCDateTime |
|
Current UTC date and time. |
UnixTime |
[utc] |
Returns current or specific Unix timestamp (seconds). |
UnixTimeMSec |
[utc] |
Returns Unix timestamp in milliseconds. |
EncodeDateTime |
y, m, d, h, n, s, ms |
Creates TDateTime from components. |
DecodeDateTime |
dt, var y, m, d, h, n, s, ms |
Extracts components from TDateTime. |
FormatDateTime |
fmt, dt [, zone] |
Formats date using pattern. |
ISO8601ToDateTime |
s |
Parses ISO8601 string. |
DateTimeToISO8601 |
dt |
Converts to ISO8601 string. |
DateTimeToRFC822 |
dt |
Converts to RFC 822 string (used in RSS/Email). |
IncYear / IncMonth / IncDay |
dt, n |
Increment/Decrement date components. |
DayOfWeek |
dt |
Returns 1 (Sunday) to 7 (Saturday). |
IsLeapYear |
year |
Primality test. |
Sleep |
msec |
Pauses execution for msec milliseconds. |
var dt := EncodeDate(2026, 1, 12) + EncodeTime(12, 0, 0, 0);
PrintLn('Full: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', dt));
PrintLn('Formatted: ' + FormatDateTime('yyyy-mm-dd', dt));
var tomorrow := dt + 1.0;
PrintLn('Tomorrow: ' + FormatDateTime('yyyy-mm-dd hh:nn:ss', tomorrow)); Full: 2026-01-12 12:00:00 Formatted: 2026-01-12 Tomorrow: 2026-01-13 12:00:00
Since TDateTime is a Float, you can perform arithmetic directly. For example, Now + 1.0 represents tomorrow at the same time, and Now + (1.0 / 24.0) represents one hour from now.