Skip to main content

ExcelDateTime

Struct ExcelDateTime 

Source
pub struct ExcelDateTime { /* private fields */ }
Expand description

Structure for Excel date and time representation.

Implementations§

Source§

impl ExcelDateTime

Source

pub fn new(value: f64, datetime_type: ExcelDateTimeType, is_1904: bool) -> Self

Creates a new ExcelDateTime

Source

pub fn is_duration(&self) -> bool

True if excel datetime has duration format ([hh]:mm:ss, for example)

Source

pub fn is_datetime(&self) -> bool

True if excel datetime has datetime format (not duration)

Source

pub fn as_f64(&self) -> f64

Converting data type into a float

Source

pub fn to_ymd_hms_milli(&self) -> (u16, u8, u8, u8, u8, u8, u16)

Convert an Excel serial datetime to standard date components.

Datetimes in Excel are serial dates with days counted from an epoch (usually 1900-01-01) and where the time is a percentage/decimal of the milliseconds in the day. Both the date and time are stored in the same f64 value. For example, 2025/10/13 12:00:00 is stored as 45943.5.

This function returns a tuple of (year, month, day, hour, minutes, seconds, milliseconds). It works for serial dates in both the 1900 and 1904 epochs.

This function always returns a date, even if the serial value is outside of Excel’s range of 0.0 <= datetime < 10000.0. It also returns, as Excel does, the invalid date 1900/02/29 due to the Excel 1900 leap year bug.

Excel only supports millisecond precision and it also doesn’t use or encode timezone information in any way.

§Examples

An example of converting an Excel date/time to standard components.

use calamine::{ExcelDateTime, ExcelDateTimeType};

// Create an Excel datetime from the serial value 45943.541 which is
// equivalent to the date "2025/10/13 12:59:02.400".
let excel_datetime = ExcelDateTime::new(
    45943.541,
    ExcelDateTimeType::DateTime,
    false, // Using 1900 epoch (not 1904).
);

// Convert to standard date/time components.
let (year, month, day, hour, min, sec, milli) = excel_datetime.to_ymd_hms_milli();

assert_eq!(year, 2025);
assert_eq!(month, 10);
assert_eq!(day, 13);
assert_eq!(hour, 12);
assert_eq!(min, 59);
assert_eq!(sec, 2);
assert_eq!(milli, 400);
Source

pub fn as_duration(&self) -> Option<Duration>

Available on crate feature chrono only.

Try converting data type into a duration.

Source

pub fn as_datetime(&self) -> Option<NaiveDateTime>

Available on crate feature chrono only.

Try converting data type into a datetime.

Trait Implementations§

Source§

impl Clone for ExcelDateTime

Source§

fn clone(&self) -> ExcelDateTime

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ExcelDateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ExcelDateTime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for ExcelDateTime

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl PartialEq for ExcelDateTime

Source§

fn eq(&self, other: &ExcelDateTime) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for ExcelDateTime

Source§

impl StructuralPartialEq for ExcelDateTime

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.