DateValue

DateValue(arg)

Attributes

Name Description
add Add an interval to a date.
radd Add an interval to a date.
sub Subtract a date or an interval from a date.

Methods

Name Description
delta Compute the number of parts between two dates.
epoch_days Return the number of days since the UNIX epoch date.
strftime Format a date according to format_str.
truncate Truncate date expression to units of unit.

delta

delta(other, part)

Compute the number of parts between two dates.

The order of operands matches standard subtraction

The second argument is subtracted from the first.

Parameters

Name Type Description Default
other datetime.date | Value[dt.Date] A date expression required
part Literal['year', 'quarter', 'month', 'week', 'day'] | Value[dt.String] The unit of time to compute the difference in required

Returns

Name Type Description
IntegerValue The number of parts between self and other

Examples

>>> import ibis
>>> ibis.options.interactive = True
>>> start = ibis.date("1992-09-30")
>>> end = ibis.date("1992-10-01")
>>> end.delta(start, unit="day")

┌───┐
│ 1 │
└───┘
>>> prez = ibis.examples.presidential.fetch()
>>> prez.mutate(
...     years_in_office=prez.end.delta(prez.start, unit="year"),
...     hours_in_office=prez.end.delta(prez.start, unit="hour"),
... ).drop("party")
┏━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━┓
┃ name        start       end         years_in_office  hours_in_office ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━┩
│ stringdatedateint64int64           │
├────────────┼────────────┼────────────┼─────────────────┼─────────────────┤
│ Eisenhower1953-01-201961-01-20870128 │
│ Kennedy   1961-01-201963-11-22224864 │
│ Johnson   1963-11-221969-01-20645264 │
│ Nixon     1969-01-201974-08-09548648 │
│ Ford      1974-08-091977-01-20321480 │
│ Carter    1977-01-201981-01-20435064 │
│ Reagan    1981-01-201989-01-20870128 │
│ Bush      1989-01-201993-01-20435064 │
│ Clinton   1993-01-202001-01-20870128 │
│ Bush      2001-01-202009-01-20870128 │
│  │
└────────────┴────────────┴────────────┴─────────────────┴─────────────────┘

epoch_days

epoch_days()

Return the number of days since the UNIX epoch date.

Examples

>>> import ibis
>>> ibis.options.interactive = True
>>> date = ibis.date(2020, 1, 1)
>>> date

┌────────────┐
│ 2020-01-01 │
└────────────┘
>>> date.epoch_days()

┌───────┐
│ 18262 │
└───────┘
>>> t = date.name("date_col").as_table()
>>> t
┏━━━━━━━━━━━━┓
┃ date_col   ┃
┡━━━━━━━━━━━━┩
│ date       │
├────────────┤
│ 2020-01-01 │
└────────────┘
>>> t.mutate(epoch=t.date_col.epoch_days())
┏━━━━━━━━━━━━┳━━━━━━━┓
┃ date_col    epoch ┃
┡━━━━━━━━━━━━╇━━━━━━━┩
│ dateint64 │
├────────────┼───────┤
│ 2020-01-0118262 │
└────────────┴───────┘

strftime

strftime(format_str)

Format a date according to format_str.

Format string may depend on the backend, but we try to conform to ANSI strftime.

Parameters

Name Type Description Default
format_str str strftime format string required

Returns

Name Type Description
StringValue Formatted version of arg

truncate

truncate(unit)

Truncate date expression to units of unit.

Parameters

Name Type Description Default
unit Literal['Y', 'Q', 'M', 'W', 'D'] Unit to truncate arg to required

Returns

Name Type Description
DateValue Truncated date value expression