Dates and Time

Dates and Time

Functionality to handle time and dates is defined in the standard library module Dates. You'll need to import the module using import Dates and prefix each function call with an explicit Dates., e.g. Dates.dayofweek(dt). Alternatively, you can write using Dates to bring all exported functions into Main to be used without the Dates. prefix.

Dates and Time Types

Dates.PeriodType.
Period
Year
Month
Week
Day
Hour
Minute
Second
Millisecond
Microsecond
Nanosecond

Period types represent discrete, human representations of time.

source
CompoundPeriod

A CompoundPeriod is useful for expressing time periods that are not a fixed multiple of smaller periods. For example, "a year and a day" is not a fixed number of days, but can be expressed using a CompoundPeriod. In fact, a CompoundPeriod is automatically generated by addition of different period types, e.g. Year(1) + Day(1) produces a CompoundPeriod result.

source
Dates.InstantType.
Instant

Instant types represent integer-based, machine representations of time as continuous timelines starting from an epoch.

source
Dates.UTInstantType.
UTInstant{T}

The UTInstant represents a machine timeline based on UT time (1 day = one revolution of the earth). The T is a Period parameter that indicates the resolution or precision of the instant.

source
Dates.TimeTypeType.
TimeType

TimeType types wrap Instant machine instances to provide human representations of the machine instant. Time, DateTime and Date are subtypes of TimeType.

source
Dates.DateTimeType.
DateTime

DateTime wraps a UTInstant{Millisecond} and interprets it according to the proleptic Gregorian calendar.

source
Dates.DateType.
Date

Date wraps a UTInstant{Day} and interprets it according to the proleptic Gregorian calendar.

source
Dates.TimeType.
Time

Time wraps a Nanosecond and represents a specific moment in a 24-hour day.

source

Dates Functions

Dates.DateTimeMethod.
DateTime(y, [m, d, h, mi, s, ms]) -> DateTime

Construct a DateTime type by parts. Arguments must be convertible to Int64.

source
Dates.DateTimeMethod.
DateTime(periods::Period...) -> DateTime

Construct a DateTime type by Period type parts. Arguments may be in any order. DateTime parts not provided will default to the value of Dates.default(period).

source
Dates.DateTimeMethod.
DateTime(f::Function, y[, m, d, h, mi, s]; step=Day(1), limit=10000) -> DateTime

Create a DateTime through the adjuster API. The starting point will be constructed from the provided y, m, d... arguments, and will be adjusted until f::Function returns true. The step size in adjusting can be provided manually through the step keyword. limit provides a limit to the max number of iterations the adjustment API will pursue before throwing an error (in the case that f::Function is never satisfied).

Examples

julia> DateTime(dt -> Dates.second(dt) == 40, 2010, 10, 20, 10; step = Dates.Second(1))
2010-10-20T10:00:40

julia> DateTime(dt -> Dates.hour(dt) == 20, 2010, 10, 20, 10; step = Dates.Hour(1), limit = 5)
ERROR: ArgumentError: Adjustment limit reached: 5 iterations
Stacktrace:
[...]
source
Dates.DateTimeMethod.
DateTime(dt::Date) -> DateTime

Convert a Date to a DateTime. The hour, minute, second, and millisecond parts of the new DateTime are assumed to be zero.

source
Dates.DateTimeMethod.
DateTime(dt::AbstractString, format::AbstractString; locale="english") -> DateTime

Construct a DateTime by parsing the dt date time string following the pattern given in the format string.

This method creates a DateFormat object each time it is called. If you are parsing many date time strings of the same format, consider creating a DateFormat object once and using that as the second argument instead.

source
Dates.formatFunction.
format(io::IO, tok::AbstractDateToken, dt::TimeType, locale)

Format the tok token from dt and write it to io. The formatting can be based on locale.

All subtypes of AbstractDateToken must define this method in order to be able to print a Date / DateTime object according to a DateFormat containing that token.

source
DateFormat(format::AbstractString, locale="english") -> DateFormat

Construct a date formatting object that can be used for parsing date strings or formatting a date object as a string. The following character codes can be used to construct the format string:

CodeMatchesComment
y1996, 96Returns year of 1996, 0096
Y1996, 96Returns year of 1996, 0096. Equivalent to y
m1, 01Matches 1 or 2-digit months
uJanMatches abbreviated months according to the locale keyword
UJanuaryMatches full month names according to the locale keyword
d1, 01Matches 1 or 2-digit days
H00Matches hours
M00Matches minutes
S00Matches seconds
s.500Matches milliseconds
eMon, TuesMatches abbreviated days of the week
EMondayMatches full name days of the week
yyyymmdd19960101Matches fixed-width year, month, and day

Characters not listed above are normally treated as delimiters between date and time slots. For example a dt string of "1996-01-15T00:00:00.0" would have a format string like "y-m-dTH:M:S.s". If you need to use a code character as a delimiter you can escape it using backslash. The date "1995y01m" would have the format "y\ym\m".

Creating a DateFormat object is expensive. Whenever possible, create it once and use it many times or try the dateformat"" string macro. Using this macro creates the DateFormat object once at macro expansion time and reuses it later. see @dateformat_str.

See DateTime and format for how to use a DateFormat object to parse and write Date strings respectively.

source
dateformat"Y-m-d H:M:S"

Create a DateFormat object. Similar to DateFormat("Y-m-d H:M:S") but creates the DateFormat object once during macro expansion.

See DateFormat for details about format specifiers.

source
Dates.DateTimeMethod.
DateTime(dt::AbstractString, df::DateFormat) -> DateTime

Construct a DateTime by parsing the dt date time string following the pattern given in the DateFormat object. Similar to DateTime(::AbstractString, ::AbstractString) but more efficient when repeatedly parsing similarly formatted date time strings with a pre-created DateFormat object.

source
Dates.DateMethod.
Date(y, [m, d]) -> Date

Construct a Date type by parts. Arguments must be convertible to Int64.

source
Dates.DateMethod.
Date(period::Period...) -> Date

Construct a Date type by Period type parts. Arguments may be in any order. Date parts not provided will default to the value of Dates.default(period).

source
Dates.DateMethod.
Date(f::Function, y[, m, d]; step=Day(1), limit=10000) -> Date

Create a Date through the adjuster API. The starting point will be constructed from the provided y, m, d arguments, and will be adjusted until f::Function returns true. The step size in adjusting can be provided manually through the step keyword. limit provides a limit to the max number of iterations the adjustment API will pursue before throwing an error (given that f::Function is never satisfied).

Examples

julia> Date(date -> Dates.week(date) == 20, 2010, 01, 01)
2010-05-17

julia> Date(date -> Dates.year(date) == 2010, 2000, 01, 01)
2010-01-01

julia> Date(date -> Dates.month(date) == 10, 2000, 01, 01; limit = 5)
ERROR: ArgumentError: Adjustment limit reached: 5 iterations
Stacktrace:
[...]
source
Dates.DateMethod.
Date(dt::DateTime) -> Date

Convert a DateTime to a Date. The hour, minute, second, and millisecond parts of the DateTime are truncated, so only the year, month and day parts are used in construction.

source
Dates.DateMethod.
Date(d::AbstractString, format::AbstractString; locale="english") -> Date

Construct a Date by parsing the d date string following the pattern given in the format string.

This method creates a DateFormat object each time it is called. If you are parsing many date strings of the same format, consider creating a DateFormat object once and using that as the second argument instead.

source
Dates.DateMethod.
Date(d::AbstractString, df::DateFormat) -> Date

Parse a date from a date string d using a DateFormat object df.

source
Dates.TimeMethod.
Time(h, [mi, s, ms, us, ns]) -> Time

Construct a Time type by parts. Arguments must be convertible to Int64.

source
Dates.TimeMethod.
Time(period::TimePeriod...) -> Time

Construct a Time type by Period type parts. Arguments may be in any order. Time parts not provided will default to the value of Dates.default(period).

source
Dates.TimeMethod.
Time(f::Function, h, mi=0; step::Period=Second(1), limit::Int=10000)
Time(f::Function, h, mi, s; step::Period=Millisecond(1), limit::Int=10000)
Time(f::Function, h, mi, s, ms; step::Period=Microsecond(1), limit::Int=10000)
Time(f::Function, h, mi, s, ms, us; step::Period=Nanosecond(1), limit::Int=10000)

Create a Time through the adjuster API. The starting point will be constructed from the provided h, mi, s, ms, us arguments, and will be adjusted until f::Function returns true. The step size in adjusting can be provided manually through the step keyword. limit provides a limit to the max number of iterations the adjustment API will pursue before throwing an error (in the case that f::Function is never satisfied). Note that the default step will adjust to allow for greater precision for the given arguments; i.e. if hour, minute, and second arguments are provided, the default step will be Millisecond(1) instead of Second(1).

Examples

julia> Dates.Time(t -> Dates.minute(t) == 30, 20)
20:30:00

julia> Dates.Time(t -> Dates.minute(t) == 0, 20)
20:00:00

julia> Dates.Time(t -> Dates.hour(t) == 10, 3; limit = 5)
ERROR: ArgumentError: Adjustment limit reached: 5 iterations
Stacktrace:
[...]
source
Dates.TimeMethod.
Time(dt::DateTime) -> Time

Convert a DateTime to a Time. The hour, minute, second, and millisecond parts of the DateTime are used to create the new Time. Microsecond and nanoseconds are zero by default.

source
Dates.nowMethod.
now() -> DateTime

Return a DateTime corresponding to the user's system time including the system timezone locale.

source
Dates.nowMethod.
now(::Type{UTC}) -> DateTime

Return a DateTime corresponding to the user's system time as UTC/GMT.

source
Base.epsFunction.
eps(::DateTime) -> Millisecond
eps(::Date) -> Day
eps(::Time) -> Nanosecond

Returns Millisecond(1) for DateTime values, Day(1) for Date values, and Nanosecond(1) for Time values.

source

Accessor Functions

Dates.yearFunction.
year(dt::TimeType) -> Int64

The year of a Date or DateTime as an Int64.

source
Dates.monthFunction.
month(dt::TimeType) -> Int64

The month of a Date or DateTime as an Int64.

source
Dates.weekFunction.
week(dt::TimeType) -> Int64

Return the ISO week date of a Date or DateTime as an Int64. Note that the first week of a year is the week that contains the first Thursday of the year, which can result in dates prior to January 4th being in the last week of the previous year. For example, week(Date(2005, 1, 1)) is the 53rd week of 2004.

Examples

julia> Dates.week(Date(1989, 6, 22))
25

julia> Dates.week(Date(2005, 1, 1))
53

julia> Dates.week(Date(2004, 12, 31))
53
source
Dates.dayFunction.
day(dt::TimeType) -> Int64

The day of month of a Date or DateTime as an Int64.

source
Dates.hourFunction.
hour(dt::DateTime) -> Int64

The hour of day of a DateTime as an Int64.

source
hour(t::Time) -> Int64

The hour of a Time as an Int64.

source
Dates.minuteFunction.
minute(dt::DateTime) -> Int64

The minute of a DateTime as an Int64.

source
minute(t::Time) -> Int64

The minute of a Time as an Int64.

source
Dates.secondFunction.
second(dt::DateTime) -> Int64

The second of a DateTime as an Int64.

source
second(t::Time) -> Int64

The second of a Time as an Int64.

source
Dates.millisecondFunction.
millisecond(dt::DateTime) -> Int64

The millisecond of a DateTime as an Int64.

source
millisecond(t::Time) -> Int64

The millisecond of a Time as an Int64.

source
Dates.microsecondFunction.
microsecond(t::Time) -> Int64

The microsecond of a Time as an Int64.

source
Dates.nanosecondFunction.
nanosecond(t::Time) -> Int64

The nanosecond of a Time as an Int64.

source
Dates.YearMethod.
Year(v)

Construct a Year object with the given v value. Input must be losslessly convertible to an Int64.

source
Dates.MonthMethod.
Month(v)

Construct a Month object with the given v value. Input must be losslessly convertible to an Int64.

source
Dates.WeekMethod.
Week(v)

Construct a Week object with the given v value. Input must be losslessly convertible to an Int64.

source
Dates.DayMethod.
Day(v)

Construct a Day object with the given v value. Input must be losslessly convertible to an Int64.

source
Dates.HourMethod.
Hour(dt::DateTime) -> Hour

The hour part of a DateTime as a Hour.

source
Dates.MinuteMethod.
Minute(dt::DateTime) -> Minute

The minute part of a DateTime as a Minute.

source
Dates.SecondMethod.
Second(dt::DateTime) -> Second

The second part of a DateTime as a Second.

source
Dates.MillisecondMethod.
Millisecond(dt::DateTime) -> Millisecond

The millisecond part of a DateTime as a Millisecond.

source
Dates.MicrosecondMethod.
Microsecond(dt::Time) -> Microsecond

The microsecond part of a Time as a Microsecond.

source
Dates.NanosecondMethod.
Nanosecond(dt::Time) -> Nanosecond

The nanosecond part of a Time as a Nanosecond.

source
Dates.yearmonthFunction.
yearmonth(dt::TimeType) -> (Int64, Int64)

Simultaneously return the year and month parts of a Date or DateTime.

source
Dates.monthdayFunction.
monthday(dt::TimeType) -> (Int64, Int64)

Simultaneously return the month and day parts of a Date or DateTime.

source
Dates.yearmonthdayFunction.
yearmonthday(dt::TimeType) -> (Int64, Int64, Int64)

Simultaneously return the year, month and day parts of a Date or DateTime.

source

Query Functions

Dates.daynameFunction.
dayname(dt::TimeType; locale="english") -> String

Return the full day name corresponding to the day of the week of the Date or DateTime in the given locale.

Examples

julia> Dates.dayname(Date("2000-01-01"))
"Saturday"
source
Dates.dayabbrFunction.
dayabbr(dt::TimeType; locale="english") -> String

Return the abbreviated name corresponding to the day of the week of the Date or DateTime in the given locale.

Examples

julia> Dates.dayabbr(Date("2000-01-01"))
"Sat"
source
Dates.dayofweekFunction.
dayofweek(dt::TimeType) -> Int64

Return the day of the week as an Int64 with 1 = Monday, 2 = Tuesday, etc..

Examples

julia> Dates.dayofweek(Date("2000-01-01"))
6
source
Dates.dayofmonthFunction.
dayofmonth(dt::TimeType) -> Int64

The day of month of a Date or DateTime as an Int64.

source
dayofweekofmonth(dt::TimeType) -> Int

For the day of week of dt, return which number it is in dt's month. So if the day of the week of dt is Monday, then 1 = First Monday of the month, 2 = Second Monday of the month, etc. In the range 1:5.

Examples

```jldoctest julia> Dates.dayofweekofmonth(Date("2000-02-01")) 1

julia> Dates.dayofweekofmonth(Date("2000-02-08")) 2

julia> Dates.dayofweekofmonth(Date("2000-02-15")) 3 ````

source
daysofweekinmonth(dt::TimeType) -> Int

For the day of week of dt, return the total number of that day of the week in dt's month. Returns 4 or 5. Useful in temporal expressions for specifying the last day of a week in a month by including dayofweekofmonth(dt) == daysofweekinmonth(dt) in the adjuster function.

Examples

julia> Dates.daysofweekinmonth(Date("2005-01-01"))
5

julia> Dates.daysofweekinmonth(Date("2005-01-04"))
4
source
Dates.monthnameFunction.
monthname(dt::TimeType; locale="english") -> String

Return the full name of the month of the Date or DateTime in the given locale.

Examples

julia> Dates.monthname(Date("2005-01-04"))
"January"
source
Dates.monthabbrFunction.
monthabbr(dt::TimeType; locale="english") -> String

Return the abbreviated month name of the Date or DateTime in the given locale.

Examples

julia> Dates.monthabbr(Date("2005-01-04"))
"Jan"
source
Dates.daysinmonthFunction.
daysinmonth(dt::TimeType) -> Int

Return the number of days in the month of dt. Value will be 28, 29, 30, or 31.

Examples

julia> Dates.daysinmonth(Date("2000-01"))
31

julia> Dates.daysinmonth(Date("2001-02"))
28

julia> Dates.daysinmonth(Date("2000-02"))
29
source
Dates.isleapyearFunction.
isleapyear(dt::TimeType) -> Bool

Return true if the year of dt is a leap year.

Examples

julia> Dates.isleapyear(Date("2004"))
true

julia> Dates.isleapyear(Date("2005"))
false
source
Dates.dayofyearFunction.
dayofyear(dt::TimeType) -> Int

Return the day of the year for dt with January 1st being day 1.

source
Dates.daysinyearFunction.
daysinyear(dt::TimeType) -> Int

Return 366 if the year of dt is a leap year, otherwise return 365.

Examples

julia> Dates.daysinyear(1999)
365

julia> Dates.daysinyear(2000)
366
source
Dates.quarterofyearFunction.
quarterofyear(dt::TimeType) -> Int

Return the quarter that dt resides in. Range of value is 1:4.

source
Dates.dayofquarterFunction.
dayofquarter(dt::TimeType) -> Int

Return the day of the current quarter of dt. Range of value is 1:92.

source

Adjuster Functions

Base.truncMethod.
trunc(dt::TimeType, ::Type{Period}) -> TimeType

Truncates the value of dt according to the provided Period type.

Examples

julia> trunc(Dates.DateTime("1996-01-01T12:30:00"), Dates.Day)
1996-01-01T00:00:00
source
Dates.firstdayofweekFunction.
firstdayofweek(dt::TimeType) -> TimeType

Adjusts dt to the Monday of its week.

Examples

julia> Dates.firstdayofweek(DateTime("1996-01-05T12:30:00"))
1996-01-01T00:00:00
source
Dates.lastdayofweekFunction.
lastdayofweek(dt::TimeType) -> TimeType

Adjusts dt to the Sunday of its week.

Examples

julia> Dates.lastdayofweek(DateTime("1996-01-05T12:30:00"))
1996-01-07T00:00:00
source
Dates.firstdayofmonthFunction.
firstdayofmonth(dt::TimeType) -> TimeType

Adjusts dt to the first day of its month.

Examples

julia> Dates.firstdayofmonth(DateTime("1996-05-20"))
1996-05-01T00:00:00
source
Dates.lastdayofmonthFunction.
lastdayofmonth(dt::TimeType) -> TimeType

Adjusts dt to the last day of its month.

Examples

julia> Dates.lastdayofmonth(DateTime("1996-05-20"))
1996-05-31T00:00:00
source
Dates.firstdayofyearFunction.
firstdayofyear(dt::TimeType) -> TimeType

Adjusts dt to the first day of its year.

Examples

julia> Dates.firstdayofyear(DateTime("1996-05-20"))
1996-01-01T00:00:00
source
Dates.lastdayofyearFunction.
lastdayofyear(dt::TimeType) -> TimeType

Adjusts dt to the last day of its year.

Examples

julia> Dates.lastdayofyear(DateTime("1996-05-20"))
1996-12-31T00:00:00
source
firstdayofquarter(dt::TimeType) -> TimeType

Adjusts dt to the first day of its quarter.

Examples

julia> Dates.firstdayofquarter(DateTime("1996-05-20"))
1996-04-01T00:00:00

julia> Dates.firstdayofquarter(DateTime("1996-08-20"))
1996-07-01T00:00:00
source
lastdayofquarter(dt::TimeType) -> TimeType

Adjusts dt to the last day of its quarter.

Examples

julia> Dates.lastdayofquarter(DateTime("1996-05-20"))
1996-06-30T00:00:00

julia> Dates.lastdayofquarter(DateTime("1996-08-20"))
1996-09-30T00:00:00
source
Dates.tonextMethod.
tonext(dt::TimeType, dow::Int; same::Bool=false) -> TimeType

Adjusts dt to the next day of week corresponding to dow with 1 = Monday, 2 = Tuesday, etc. Setting same=true allows the current dt to be considered as the next dow, allowing for no adjustment to occur.

source
Dates.toprevMethod.
toprev(dt::TimeType, dow::Int; same::Bool=false) -> TimeType

Adjusts dt to the previous day of week corresponding to dow with 1 = Monday, 2 = Tuesday, etc. Setting same=true allows the current dt to be considered as the previous dow, allowing for no adjustment to occur.

source
Dates.tofirstFunction.
tofirst(dt::TimeType, dow::Int; of=Month) -> TimeType

Adjusts dt to the first dow of its month. Alternatively, of=Year will adjust to the first dow of the year.

source
Dates.tolastFunction.
tolast(dt::TimeType, dow::Int; of=Month) -> TimeType

Adjusts dt to the last dow of its month. Alternatively, of=Year will adjust to the last dow of the year.

source
Dates.tonextMethod.
tonext(func::Function, dt::TimeType; step=Day(1), limit=10000, same=false) -> TimeType

Adjusts dt by iterating at most limit iterations by step increments until func returns true. func must take a single TimeType argument and return a Bool. same allows dt to be considered in satisfying func.

source
Dates.toprevMethod.
toprev(func::Function, dt::TimeType; step=Day(-1), limit=10000, same=false) -> TimeType

Adjusts dt by iterating at most limit iterations by step increments until func returns true. func must take a single TimeType argument and return a Bool. same allows dt to be considered in satisfying func.

source

Periods

Dates.PeriodMethod.
Year(v)
Month(v)
Week(v)
Day(v)
Hour(v)
Minute(v)
Second(v)
Millisecond(v)
Microsecond(v)
Nanosecond(v)

Construct a Period type with the given v value. Input must be losslessly convertible to an Int64.

source
CompoundPeriod(periods) -> CompoundPeriod

Construct a CompoundPeriod from a Vector of Periods. All Periods of the same type will be added together.

Examples

julia> Dates.CompoundPeriod(Dates.Hour(12), Dates.Hour(13))
25 hours

julia> Dates.CompoundPeriod(Dates.Hour(-1), Dates.Minute(1))
-1 hour, 1 minute

julia> Dates.CompoundPeriod(Dates.Month(1), Dates.Week(-2))
1 month, -2 weeks

julia> Dates.CompoundPeriod(Dates.Minute(50000))
50000 minutes
source
Dates.defaultFunction.
default(p::Period) -> Period

Returns a sensible "default" value for the input Period by returning T(1) for Year, Month, and Day, and T(0) for Hour, Minute, Second, and Millisecond.

source

Rounding Functions

Date and DateTime values can be rounded to a specified resolution (e.g., 1 month or 15 minutes) with floor, ceil, or round.

Base.floorMethod.
floor(dt::TimeType, p::Period) -> TimeType

Return the nearest Date or DateTime less than or equal to dt at resolution p.

For convenience, p may be a type instead of a value: floor(dt, Dates.Hour) is a shortcut for floor(dt, Dates.Hour(1)).

julia> floor(Date(1985, 8, 16), Dates.Month)
1985-08-01

julia> floor(DateTime(2013, 2, 13, 0, 31, 20), Dates.Minute(15))
2013-02-13T00:30:00

julia> floor(DateTime(2016, 8, 6, 12, 0, 0), Dates.Day)
2016-08-06T00:00:00
source
Base.ceilMethod.
ceil(dt::TimeType, p::Period) -> TimeType

Return the nearest Date or DateTime greater than or equal to dt at resolution p.

For convenience, p may be a type instead of a value: ceil(dt, Dates.Hour) is a shortcut for ceil(dt, Dates.Hour(1)).

julia> ceil(Date(1985, 8, 16), Dates.Month)
1985-09-01

julia> ceil(DateTime(2013, 2, 13, 0, 31, 20), Dates.Minute(15))
2013-02-13T00:45:00

julia> ceil(DateTime(2016, 8, 6, 12, 0, 0), Dates.Day)
2016-08-07T00:00:00
source
Base.roundMethod.
round(dt::TimeType, p::Period, [r::RoundingMode]) -> TimeType

Return the Date or DateTime nearest to dt at resolution p. By default (RoundNearestTiesUp), ties (e.g., rounding 9:30 to the nearest hour) will be rounded up.

For convenience, p may be a type instead of a value: round(dt, Dates.Hour) is a shortcut for round(dt, Dates.Hour(1)).

julia> round(Date(1985, 8, 16), Dates.Month)
1985-08-01

julia> round(DateTime(2013, 2, 13, 0, 31, 20), Dates.Minute(15))
2013-02-13T00:30:00

julia> round(DateTime(2016, 8, 6, 12, 0, 0), Dates.Day)
2016-08-07T00:00:00

Valid rounding modes for round(::TimeType, ::Period, ::RoundingMode) are RoundNearestTiesUp (default), RoundDown (floor), and RoundUp (ceil).

source

Most Period values can also be rounded to a specified resolution:

Base.floorMethod.
floor(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> T

Round x down to the nearest multiple of precision. If x and precision are different subtypes of Period, the return value will have the same type as precision.

For convenience, precision may be a type instead of a value: floor(x, Dates.Hour) is a shortcut for floor(x, Dates.Hour(1)).

julia> floor(Dates.Day(16), Dates.Week)
2 weeks

julia> floor(Dates.Minute(44), Dates.Minute(15))
30 minutes

julia> floor(Dates.Hour(36), Dates.Day)
1 day

Rounding to a precision of Months or Years is not supported, as these Periods are of inconsistent length.

source
Base.ceilMethod.
ceil(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> T

Round x up to the nearest multiple of precision. If x and precision are different subtypes of Period, the return value will have the same type as precision.

For convenience, precision may be a type instead of a value: ceil(x, Dates.Hour) is a shortcut for ceil(x, Dates.Hour(1)).

julia> ceil(Dates.Day(16), Dates.Week)
3 weeks

julia> ceil(Dates.Minute(44), Dates.Minute(15))
45 minutes

julia> ceil(Dates.Hour(36), Dates.Day)
3 days

Rounding to a precision of Months or Years is not supported, as these Periods are of inconsistent length.

source
Base.roundMethod.
round(x::Period, precision::T, [r::RoundingMode]) where T <: Union{TimePeriod, Week, Day} -> T

Round x to the nearest multiple of precision. If x and precision are different subtypes of Period, the return value will have the same type as precision. By default (RoundNearestTiesUp), ties (e.g., rounding 90 minutes to the nearest hour) will be rounded up.

For convenience, precision may be a type instead of a value: round(x, Dates.Hour) is a shortcut for round(x, Dates.Hour(1)).

julia> round(Dates.Day(16), Dates.Week)
2 weeks

julia> round(Dates.Minute(44), Dates.Minute(15))
45 minutes

julia> round(Dates.Hour(36), Dates.Day)
3 days

Valid rounding modes for round(::Period, ::T, ::RoundingMode) are RoundNearestTiesUp (default), RoundDown (floor), and RoundUp (ceil).

Rounding to a precision of Months or Years is not supported, as these Periods are of inconsistent length.

source

The following functions are not exported:

Dates.floorceilFunction.
floorceil(dt::TimeType, p::Period) -> (TimeType, TimeType)

Simultaneously return the floor and ceil of a Date or DateTime at resolution p. More efficient than calling both floor and ceil individually.

source
floorceil(x::Period, precision::T) where T <: Union{TimePeriod, Week, Day} -> (T, T)

Simultaneously return the floor and ceil of Period at resolution p. More efficient than calling both floor and ceil individually.

source
Dates.epochdays2dateFunction.
epochdays2date(days) -> Date

Take the number of days since the rounding epoch (0000-01-01T00:00:00) and return the corresponding Date.

source
epochms2datetime(milliseconds) -> DateTime

Take the number of milliseconds since the rounding epoch (0000-01-01T00:00:00) and return the corresponding DateTime.

source
Dates.date2epochdaysFunction.
date2epochdays(dt::Date) -> Int64

Take the given Date and return the number of days since the rounding epoch (0000-01-01T00:00:00) as an Int64.

source
datetime2epochms(dt::DateTime) -> Int64

Take the given DateTime and return the number of milliseconds since the rounding epoch (0000-01-01T00:00:00) as an Int64.

source

Conversion Functions

Dates.todayFunction.
today() -> Date

Return the date portion of now().

source
Dates.unix2datetimeFunction.
unix2datetime(x) -> DateTime

Take the number of seconds since unix epoch 1970-01-01T00:00:00 and convert to the corresponding DateTime.

source
Dates.datetime2unixFunction.
datetime2unix(dt::DateTime) -> Float64

Take the given DateTime and return the number of seconds since the unix epoch 1970-01-01T00:00:00 as a Float64.

source
Dates.julian2datetimeFunction.
julian2datetime(julian_days) -> DateTime

Take the number of Julian calendar days since epoch -4713-11-24T12:00:00 and return the corresponding DateTime.

source
Dates.datetime2julianFunction.
datetime2julian(dt::DateTime) -> Float64

Take the given DateTime and return the number of Julian calendar days since the julian epoch -4713-11-24T12:00:00 as a Float64.

source
Dates.rata2datetimeFunction.
rata2datetime(days) -> DateTime

Take the number of Rata Die days since epoch 0000-12-31T00:00:00 and return the corresponding DateTime.

source
Dates.datetime2rataFunction.
datetime2rata(dt::TimeType) -> Int64

Return the number of Rata Die days since epoch from the given Date or DateTime.

source

Constants

Days of the Week:

VariableAbbr.Value (Int)
MondayMon1
TuesdayTue2
WednesdayWed3
ThursdayThu4
FridayFri5
SaturdaySat6
SundaySun7

Months of the Year:

VariableAbbr.Value (Int)
JanuaryJan1
FebruaryFeb2
MarchMar3
AprilApr4
MayMay5
JuneJun6
JulyJul7
AugustAug8
SeptemberSep9
OctoberOct10
NovemberNov11
DecemberDec12