theagilecoder
Insert Ecto schemas in Postgres in the Indian Time Zone (IST - Indian Standard Time)?
Ecto inserts a schema in postgres in the inserted_at and updated_at column without any timezone. How can make these times be in IST Timzone (Indian Standard Time) ?
Marked As Solved
kokolegorille
Also Liked
baldwindavid
I think you were getting some confusion from respondents because I believe it is more common to store past times as UTC and to then convert to the desired timezone after grabbing from the database.
I have mostly used the Timex library (Timex — timex v3.7.13) to perform this conversion. For example, to convert a UTC time from the database you can use to_datetime/2…
record = Repo.get(id)
Timex.to_datetime(record.inserted_at, "Asia/Calcutta")
UTC works great for past times and it sounds like that is your only concern here. For future times, you might actually want to store the timezone and “wall” time in the database. I use the Calecto calendar_datetime custom type (GitHub - lau/calecto: Adapter for the Calendar library in Ecto · GitHub) to store future event times. This should help protect against timezone changes in between the time the event is stored and when it actually takes place.
As an aside, if someone “really” wanted to store past times in a specific time zone, they could probably do so with the Calecto custom type.
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
- #code-sync
- #javascript
- #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
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









