Anyone have any luck with a String
to DateTime
kinda function in Elixir or Phoenix? The documentation has nothing like a parse/1
function.
Preferably from a string that looks like:
08/02/2016 6:15 PM
There's no such function in Elixir or Phoenix. Ecto has some basic datetime parsers but they cannot parse the example string you've posted. You can use a datetime library like timex
for this. Here's how you would parse the example string with timex:
iex(1)> Timex.parse("08/02/2016 6:15 PM", "{0D}/{0M}/{YYYY} {h12}:{m} {AM}")
{:ok, ~N[2016-02-08 18:15:00]}
(Swap 0D
and 0M
if you meant this date to parse to Aug 2 instead of Feb 8.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With