Elixir Ecto DateTime Tuple conversion

ecto

#1

Hello,

Good day to you all…
Can someone assist me convert this datetime tuple to a normal date and time, please?

{{2019, 1, 10}, {16, 46, 8, 25301}}

I would be very grateful for your support.

Thanks.

Jerry


#2

What do you mean by this?

Also you have not specified how to treat the 4th element in the second tuple. Milli-, micro-, nanoseconds or even pico or something totally different? Where do you get this from, perhaps that package already gives you the necessary tools to convert?


#3

Hello @NobbZ,

I need want to convert the tuple to YYYY-MM-DD HH:MI:SS format.
The fourth element is the microsecond which I do not need.

I am getting this from Ecto Query result:

%{
  created_at: {{2019, 1, 10}, {16, 46, 8, 25301}},
  id: 2,
  info_id: 238,
  manuf_date: {{2019, 1, 10}, {0, 0, 0, 0}},
  rel_date: {{2019, 1, 10}, {0, 0, 0, 0}},
  updated_at: {{2019, 1, 10}, {16, 46, 8, 25301}}
}

Thanks.


#4

Of what type are those fields in your schema?

But perhaps How to convert db timestamp to NaiveDateTime and following posts can help you figure it out.


#5

Hi @NobbZ,

Inside my Ecto schema, I have this:

    field :manufacture_date, :utc_datetime 
    field :release_date, :utc_datetime 
    field :created_at, :utc_datetime
    field :updated_at, :utc_datetime 

and inside the database, these fields are declared as timestamp.

Thanks.