hassanRsiddiqi

hassanRsiddiqi

Timex parsing format 22-AUG-18

Hi,
I’m having hard time parsing a date format: 22-AUG-18 while using {:timex, "~> 3.6"} , solution I have tried:

Timex.parse(“22-AUG-18”, “{D}-{WDshort}-{YYYY}”)
{:error, “Expected weekday abbreviation at line 1, column 4.”}
Timex.parse(“22-AUG-18”, “{D}-{Mshort}-{YY}”)
{:error, “Expected month abbreviation at line 1, column 7.”}
Timex.parse!(“22-AUG-18”, “%d-%^b-%y”)
Timex.parse!(“22-AUG-18”, “%d-%b-%y”)

Thanks in advance

Marked As Solved

outlog

outlog

"22-AUG-18" 
|> String.split("-")
|> Enum.map(&String.capitalize(&1)) 
|> Enum.join("-") 
|> Timex.parse("{D}-{Mshort}-{YY}")

@OvermindDL1 great to have you back!

Also Liked

Marcus

Marcus

You can also use datix and tox:

iex> months = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ]
iex> format = "%d-%b-%y"
iex> parse = fn(date) ->
...>   date
...>   |> Datix.Date.parse!(format, abbreviated_month_names: months)
...>   |> Tox.Date.shift(year: 2000)
...> end
iex> date = parse.("22-AUG-18")
~D[2018-08-22]
iex> Calendar.strftime(date, format, abbreviated_month_names: fn x -> Enum.at(months, x - 1) end)
"22-AUG-18"
OvermindDL1

OvermindDL1

Yep, that’s exactly the mapping before hand, quite easy. ^.^

Baby is so busy! Trying to be a toddler already!

Yeah it would be pretty trivial to finish it off by piping into a case and matching on the elements and parsing the strings to integers and such with a map mapping from months to a month integer.

hauleth

hauleth

As you went that far with manual parsing, then I would finish it manually instead of using Timex. Especially if you do not use any other Timex features

Where Next?

Popular in Questions Top

aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
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
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> somethi...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 53690 245
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
Please see the new poll here: Which code editor or IDE do you use? (Poll) (2022 Edition) It’s been a while since we first asked this, I...
208 31142 143
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement