Unable to format Ecto.DateTime properly using Timex

I have an Ecto.DateTime variable

#Ecto.DateTime<2017-03-10 00:00:00>

which I want to format like this:

Timex.format!(my_datetime, "%a, %d %b %Y %H:%M:%S %z", :strftime))

in order to get a time-stamp in this format:

Wed, 02 Oct 2002 08:00:00 EST or Wed, 02 Oct 2002 15:00:00 +0200

But it throws an exception:

argument error

I’ve tried other things but nothing has worked at all.

It’s funny, but this doesn’t throw an exception: Timex.format!(my_datetime, "{D}.{M}.{YYYY} {h24}:{m}") but it’s not what I want.

1 Like

It looks like you’ll need to convert the Ecto.DateTime to a tuple: https://github.com/bitwalker/timex/blob/master/docs/Formatting.md. You can do this conversion with Ecto.DateTime.dump(datetime): https://hexdocs.pm/ecto/Ecto.DateTime.html#dump/1

2 Likes

i’ll try to

1 Like