expression
Chrono Datelike components
Import Datelike to access calendar fields. Ordinal is the one-based day number within the year, not the day of the month. This example uses external crates; see the staged Cargo manifest. Expected stdout (not executed): 2024 3 1 61 Common mistake: Using a zero-based day index where an ordinal is expected.
Formal Syntax & Structure
rust syntaxrust
Datelike::{year, month, day, ordinal, weekday}Working Example
Example Snippetrust
fn main() { use chrono::{Datelike, NaiveDate}; let d = NaiveDate::from_ymd_opt(2024, 3, 1).unwrap(); println!("{} {} {} {}", d.year(), d.month(), d.day(), d.ordinal());}