I want to use Paul Schoenfelder's awesome Timex library to parse a simple string of format "YYYYMMDD" into a Timex.Parse.DateTime.t
type.
Right now, I'm doing something like this:
{:ok, dt} = Timex.parse "20161111", "{YYYYDDMM}"
** (MatchError) no match of right hand side value: {:error, {:format, "Expected at least one parser to succeed at line 1, column 0."}}
This code above, doesn't work. But when I do this:
{:ok, dt} = Timex.parse "2016", "{YYYY}"
{:ok, #<DateTime(2016-01-01T00:00:00Z)>}
I get dt
assigned as a DateTime
variable.
What am I doing wrong?
Thanks in advance :D
DD
and MM
are not valid parsers. You're probably looking for 0D
and 0M
(more date/month parsers available here).{}
Running on the latest git version of Timex:
iex> Timex.parse "20161111", "{YYYY}{0D}{0M}"
{:ok, #<DateTime(2016-11-11T00:00:00Z)>}
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