2

I went looking for a Rust crate (on lib.rs) that implements DateTime and found chrono.rs. However, I have two issues.

  1. I cannot find a function that takes a string representing an SQL date and converts that into the external representation. I found a variety of conversion functions but they all require format strings specifying how the date is laid out in the string, but I don't know what the format specifier should be. The parser for SQL is simply handing me this date as a string and I don't know how the string is formatted. (The code I am parsing is one of the tpch queries, so it includes both a date and an interval, which I'm hoping can be converted to a "duration".)

  2. The backend code which I am connecting to expects the date to be represented as a 64-bit unsigned integer. Is there a specific representation that is used for such?

(Note, I asked on the Rust discord server, but only got the answer that the task should be "easy".)

1 Answer 1

1

Chrono::NaiveDate::parse_from_str(s, fmt) mostly solved the first problem. I don't have intervals yet, but I can do dates. I do have to specify the format of the date, e.g. "%Y-%m-%d" but it seems the only option to do so.

And to get an integer, I am using the timestamp() function. That gives me a signed integer, which I can then convert to unsigned.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.