Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

age function (unit: week / month / quarter / year ) #41115

Closed
den-crane opened this issue Sep 8, 2022 · 1 comment · Fixed by #43123 or #44421
Closed

age function (unit: week / month / quarter / year ) #41115

den-crane opened this issue Sep 8, 2022 · 1 comment · Fixed by #43123 or #44421
Labels

Comments

@den-crane
Copy link
Contributor

den-crane commented Sep 8, 2022

a function should return the number of the full units ( age in years, ...)

SELECT
    toDate('2022-01-01') AS e,
    toDate('2021-12-29') AS s,
    dateDiff('month', s, e) AS month__diff,
    dateDiff('year', s, e) AS year_diff

┌──────────e─┬──────────s─┬─month__diff─┬─year_diff─┐
│ 2022-01-012021-12-2911 │
└────────────┴────────────┴─────────────┴───────────┘
SELECT
    toDate('2022-01-01') AS e,
    toDate('2021-12-29') AS s,
    age('month', s, e) AS month__diff,
    age('year', s, e) AS year_diff
┌──────────e─┬──────────s─┬─month__diff─┬─year_diff─┐
│ 2022-01-012021-12-2900 │
└────────────┴────────────┴─────────────┴───────────┘
CREATE FUNCTION age AS (e, s) -> (dateDiff('year', s, e) - ((month(s), day(s)) > (month(e), day(e))))

SELECT age(toDate('2022-01-01'), toDate('2021-12-29')) AS age

┌─age─┐
│   0 │
└─────┘
@den-crane den-crane changed the title age function ( week month quarter year - unit ) age function (unit: week / month / quarter / year ) Sep 8, 2022
@den-crane den-crane reopened this Dec 16, 2022
@den-crane
Copy link
Contributor Author

PR was reverted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant