theagilecoder

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

kokolegorille

This type does not exists, but can’t You transform utc to ist?

Also Liked

baldwindavid

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.

Where Next?

Popular in Questions Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: The documentation above suggests that while ...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

Other popular topics Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement