liveBook · Manning

NaiveDateTime

As explained in Elixir in Action, Third Edition

NaiveDateTime is the Elixir standard-library type and module for representing date-times without time-zone information.

NaiveDateTime is an Elixir higher-level type for representing a date and time without time-zone information. It sits alongside Date, Time, and DateTime as an abstraction built on Elixir’s foundational data types. section 2.4.11 section 2.8

Construct and inspect a naive date-time

Use the ~N sigil to create a NaiveDateTime value, then access fields such as year and hour. section 2.4.11

iex(1)> naive_datetime = ~N[2023-01-31 11:59:12.000007]

iex(2)> naive_datetime.year
2023

iex(3)> naive_datetime.hour
11

Interactive example of constructing a NaiveDateTime and reading its year and hour fields. section 2.4.11

How Elixir in Action, Third Edition covers it

How deep it goes
Demonstrates construction and field access, but does not explain internal representation or time-zone behavior.
Examples
Uses the ~N sigil with a date-time literal and reads its year and hour fields.
What it assumes
Assumes familiarity with Elixir’s foundational types and introduces NaiveDateTime among higher-level standard-library abstractions.
What you can do after
Evaluate NaiveDateTime values and inspect their component fields in IEx.
How it connects
Connects NaiveDateTime with Date, Time, DateTime, Erlang, and BEAM.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.