datetime Module
The datetime module handles dates, timestamps, calendar math, custom string formatting, and date comparison operations.
Importing
djazair
use datetime
Key Functions & Date Methods
| Function / Method | Description |
|---|---|
datetime.timestamp() | Returns current Unix epoch timestamp in seconds. |
datetime.ticks() | Returns high-resolution millisecond monotonic ticks for benchmarking. |
datetime.now() | Returns a Date instance representing current system time. |
datetime.fromParts(year, month, day, hour, min, sec) | Constructs a Date instance from specific calendar parts. |
datetime.isLeapYear(year) | Returns True if the specified year is a leap year. |
date.format(fmtString) | Formats date using strftime tokens (e.g. "%Y-%m-%d %H:%M:%S"). |
date.addDays(n) | Returns a new Date advanced by n days. |
date.diffInDays(otherDate) | Calculates difference in days between two dates. |
date.isBefore(otherDate) | Returns True if date occurs before otherDate. |
date.isAfter(otherDate) | Returns True if date occurs after otherDate. |
Example Usage
djazair
use datetime
let now = datetime.now()
print("Current Year: ${now.year()}")
print("Formatted: ${now.format("%Y-%m-%d %H:%M:%S")}")
# Date arithmetic
let event = datetime.fromParts(2026, 11, 1, 9, 0, 0)
let reminder = event.addDays(-7)
print("Event Date: ${event.format("%d %B %Y")}")
print("Reminder: ${reminder.format("%d %B %Y")}")
print("Days until event: ${event.diffInDays(now)}")