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

Dates are returned as days since epoch #369

Open
CalderWhite opened this issue Aug 8, 2024 · 2 comments
Open

Dates are returned as days since epoch #369

CalderWhite opened this issue Aug 8, 2024 · 2 comments

Comments

@CalderWhite
Copy link

I was running into issues querying dates in my code, and I found this stackoverflow thread: https://stackoverflow.com/questions/78576383/how-to-fetch-datetime-type-correctly-from-duckdb-using-rust

It perfectly describes my case.

My question is: Is this the behaviour we want to have in this crate going forward? If not I am happy to open a PR to fix this and return values as NaiveDateTimes/Dates in rust.

@thumbert
Copy link

thumbert commented Sep 6, 2024

Makes sense to me not to depend on chrono and leave the existing behavior as is. It's an easy conversion after all, and you can use any of the datetime crates you like.

@andrewhamon
Copy link

For future peeps struggling to convert types, here is a snippet from my json conversion code:

duckdb::types::Value::Date32(i) => {
            // From experimentation, this is number of days since 1970-01-01.
            // Chrono uses 0001-01-01 as the epoch, so we need to add 719163
            // days to get the correct date.
            let nd = NaiveDate::from_num_days_from_ce_opt(i + 719163).ok_or(anyhow!(
                "Error converting duckdb::types::Value::Date32 to chrono::NaiveDate. amount: {:?}",
                i
            ))?;
            serde_json::Value::String(nd.to_string())
        }

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

No branches or pull requests

3 participants