Mooodi
Make "timestamps()" use "utc_datetime"
By default “timestamps()” generates a timestamp in naive datetime. When and when not will it be better to use “utc_datetime” instead?
In my app I need to use the values of “timestamps()”. And in some point I need to compare the “now()” with :inserted_at and then call DateTime.diff(…) I believe that it’s better for me to use :utc_datetime in “timestamps()” , right?
Most Liked
hubertlepicki
In my opinion - yes. That’s what I use and recommend to always use. (but opinions vary on this forum)
LostKobrakai
For as long as you’re not inserting the timestamps manually (e.g. insert_all), but let ecto handle them you can basically switch them out at any time. Ecto does default to NaiveDateTime.utc_now(), so it’s going to be a utc datetime no matter what and on the db side there’s no difference between an :naive_datetime and :utc_datetime field.
Mooodi
How can I convert “inserted_at” from naive to utc so that I can use it in DateTime.diff(…) ?
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #javascript
- #code-sync
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








