🎓 A1Learner
🔍
0 of 52 lessons completed

Julia Dates and Times

A date is a value that stores one calendar day. The Dates module gives tools to build dates and read their parts.

Build and print a fixed date

This block loads the Dates module first. The date is built from fixed numbers.

using Dates
d = Date(2026, 10, 28)
println(d)

Read the weekday and the parts

dayname names the weekday. The part functions return plain numbers.

using Dates
d = Date(2026, 10, 28)
println(dayname(d))
println(year(d))
println(month(d))
println(day(d))

Move and compare dates

Adding Day(1) gives the next day. A comparison between two dates gives true or false.

using Dates
d = Date(2026, 10, 28)
println(d + Day(1))
println(d < Date(2026, 11, 1))

Example

using Dates
start = Date(2026, 10, 28)
finish = start + Day(7)
println(start)
println(dayname(start))
println(finish)
println(start < finish)

Key points

  • Dates: a standard module loaded with using Dates.
  • Build a date with Date(year, month, day).
  • Use dayname to get the name of the weekday for a date.
  • Use year, month, and day to read one part of a date.
  • Add a Day value to a date to move it forward.
  • Dates compare with the usual comparison operators.

In this example, start is the fixed date 2026-10-28 and dayname shows it is a Wednesday. Adding Day(7) moves the date one week forward to 2026-11-04. The final comparison confirms the start is before the finish.

Note

a printed date uses the year-month-day order, like 2026-10-28.

Try it Yourself

Edit the code, then press Run.

Running is simulated · JuliaHub

Exercise

What does Date(2026, 10, 28) + Day(1) print?