DateTime Methods
now()
Current date and time as a DateTime object
puts now()
→ 2026-04-02 06:21:00.946891
today()
Today's date at midnight
puts today()
→ 2026-04-02 00:00:00
date_parse(str, fmt)
Parse a string into a DateTime.
Default format is "%Y-%m-%d". Pass a custom format as the second argument
puts date_parse("02/04/2026", "%d/%m/%Y")
→ 2026-04-02 00:00:00
date_from(year, month, day, hour, minute, second)
Build a DateTime from components. Hour, minute, and second default to 0.
puts date_from(2026, 04, 02, 13, 25, 0)
→ 2026-04-02 13:25:00
.year
Integer year.
puts now().year
→ 2026
.month
Integer month.
puts now().month
→ 4
.day
Integer day of month.
puts now().day
→ 2
.hour
Integer hour (0–23).
puts now().day
→ 14
.minute
Integer minute (0–23).
puts now().minute
→ 30
.second
Integer second (0–23).
puts now().second
→ 40
.format(fmt)
Format as a string using strftime codes.
Default format is "%Y-%m-%d %H:%M:%S".
puts now().format("%d/%m/%Y")
→ 02/04/2026
.add_days(n)
Return a new DateTime n days in the future.
Negative values go backward.
puts now().add_days(5)
→ 2026-04-07 22:59:30.275494
.add_minutes(n)
Return a new DateTime n minutes in the future.
puts now().add_minutes(5)
→ 2026-04-02 23:08:00.487584
.diff_days(other)
Number of days between two DateTime values. Always positive.
puts now().diff_days(date_parse("1977-11-22", "%Y-%m-%d"))
→ 17664
.diff_seconds(other)
Number of seconds between two DateTime values. Always positive.
puts now().diff_seconds(date_parse("1977-11-22", "%Y-%m-%d"))
→ 1526252921
.weekday
Day of week as integer.
0 = Monday, 6 = Sunday.
puts now().weekday
→ 4
.is_before(other)
True if this DateTime is earlier than other.
puts now().is_before(date_parse("1977-11-22", "%Y-%m-%d"))
→ false
.is_after(other)
True if this DateTime is later than other.
puts now().is_after(date_parse("1977-11-22", "%Y-%m-%d"))
→ true
.timestamp
Unix timestamp as a Float. Seconds since 1970-01-01 00:00:00 UTC.
puts now().timestamp
→ 1775275966.768478