washeku

washeku

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.

Most Liked

radar

radar

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

washeku

washeku

i’ll try to

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
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
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
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

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
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement