The built-in Date type has been deprecated. Please use the SDK-based Date type instead.
Import the date module from the SDK:
import "sdk/date"
The SDK provides the Date struct with equivalent functionality:
import "sdk/date"
// Get current date
var today: Date = Date.today()
// Format and display
print($"Today is: {today.format("YYYY-MM-DD")}\n")
// Date arithmetic
var nextWeek: Date = today.addDays(7)
print($"Next week: {nextWeek.toIso()}\n")
// Days between dates
var birthday: Date = Date.fromYmd(2025, 6, 15)
var daysUntil: int = birthday.diffDays(today)
print($"Days until birthday: {daysUntil}\n")
See the SDK date module documentation for the complete API reference:
Date.today()- Get current local dateDate.fromYmd(year, month, day)- Create from componentsDate.fromString(str)- Parse from ISO stringDate.fromEpochDays(days)- Create from epoch daysDate.isLeapYear(year)- Check leap yearDate.daysInMonth(year, month)- Get days in month
Instance methods:
year(),month(),day()- Get componentsweekday(),dayOfYear(),epochDays()- Get derived valuesdaysInMonth(),isLeapYear()- Query methodsisWeekend(),isWeekday()- Day type checksformat(pattern),toIso(),toString()- FormattingaddDays(),addWeeks(),addMonths(),addYears()- ArithmeticdiffDays()- Days between datesstartOfMonth(),endOfMonth(),startOfYear(),endOfYear()- BoundariesisBefore(),isAfter(),equals()- Comparison
- Time - Time operations
- SDK Overview - All SDK modules
- SDK source:
sdk/date.sn