Today I Learned

hashrocket A Hashrocket project

Changing Elixir DateTime Precision

DateTime.truncate(datetime, precision)

Calling this function on a DateTime allows you to change the level of precision from microsecond, :millisecond, or :second.

now = DateTime.utc_now()
# => ~U[2023-10-09 17:52:05.305420Z]

DateTime.truncate(now, :second)
# => ~U[2023-10-09 17:52:39Z]
See More #elixir TILs
Looking for help? At Hashrocket, we 💜 Elixir! From our many Elixir client projects, to sponsoring the Chicago Elixir Meetup, to the source code for this application, we are invested in this community. Contact us today to talk about your Elixir project.