duckdb / duckdb-rs

Ergonomic bindings to duckdb for Rust
MIT License
428 stars 87 forks source link

Help: how to fetch datetime type correctly? #325

Closed alanwilter closed 4 weeks ago

alanwilter commented 1 month ago

I'm a python guy trying to do a few things in Rust.

I have this bit of code:

    for row in rows {
        let (laterality, scan_date_days, modality, file_path) = row.unwrap();
        let scan_date = NaiveDate::from_num_days_from_ce(scan_date_days);
        let file_name = Path::new(&file_path)
            .file_name()
            .unwrap()
            .to_string_lossy()
            .to_string();
        let output_file_name = format!("{}_{}", modality, file_name);
        let formatted_date = scan_date.format("%d-%b-%Y").to_string().to_uppercase();
        let patient_folder = Path::new(output_directory)
            .join(format!("{}_{}_{}", patient_id, laterality, formatted_date));

First, I'm failing to move from from_num_days_from_ce to from_num_days_from_ce_opt.

In python, scan_date_days is datetime object (e.g. datetime.date(2017, 12, 18)). And I get the right formatted_date: 18-DEC-2017. However, the rust code above is giving 16-DEC-0048.

What am I missing, please?

alanwilter commented 4 weeks ago

https://stackoverflow.com/questions/78576383/how-to-fetch-datetime-type-correctly-from-duckdb-using-rust