Difference between dates #9102
Answered
by
gforsyth
vmsaipreeth
asked this question in
Q&A
-
Hi Team, Lets say we have two date columns in a ibis table. How simply can I get the difference of these date columns in no.of days? Backend: Trino Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
gforsyth
May 2, 2024
Replies: 1 comment 1 reply
-
Hi @vmsaipreeth -- you can use the [ins] In [1]: import ibis
[ins] In [2]: from datetime import date
[ins] In [3]: ibis.options.interactive = True
[ins] In [4]: con = ibis.trino.connect(
...: user="user",
...: password="",
...: host="localhost",
...: port=8080,
...: database="memory",
...: schema="default",
...: )
[ins] In [5]: ibis.set_backend(con)
[ins] In [6]: t = ibis.memtable(
...: dict(
...: start_col=[date(2024, 4, 29)],
...: end_col=[date(2025, 4, 29)],
...: ),
...: )
[ins] In [7]: t.end_col.delta(t.start_col, "day")
Out[7]:
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ DateDelta('day', end_col, start_col) ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
│ int64 │
├──────────────────────────────────────┤
│ 365 │
└──────────────────────────────────────┘ |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cpcloud
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @vmsaipreeth -- you can use the
delta
method and specify `day' as the unit: