bgpratt2000
How to convert a Date struct to an easily readable string?
Hi!
My goal is to convert the Date struct to an easily-readable string version of that date.
For example:
~D[2000-01-15] would be converted to “January 15th, 2024”.
Does anyone know of a function or library that already does this?
Thanks!!!
Most Liked
benwilson512
Author of Craft GraphQL APIs in Elixir with Absinthe
The function you’re looking for is this one: Calendar.strftime/3
That will let you pass in the date and then a format string in which you can specify things like the full name of the month, date, etc.
6
mudasobwa
Creator of Cure
Nah
The below is the real overusing of Elixir killer features:
defmodule DayEnding do
Enum.each(1..31, fn
day when div(day, 10) == 1 -> def ending(unquote(day)), do: "th"
day when rem(day, 10) == 1 -> def ending(unquote(day)), do: "st"
day when rem(day, 10) == 2 -> def ending(unquote(day)), do: "nd"
day when rem(day, 10) == 3 -> def ending(unquote(day)), do: "rd"
day -> def ending(unquote(day)), do: "th"
end)
end
4
ibarch
It could be implemented somewhere in Cldr.Calendars or Cldr.Numbers. If it isn’t, or if you’re not willing to add an extra dependency, writing your own implementation is straightforward:
def ending(day) when day in [1, 21, 31], do: "st"
def ending(day) when day in [2, 22], do: "nd"
def ending(day) when day in [3, 23], do: "rd"
def ending(_), do: "th"
3
Popular in Questions
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
** (DBConnection.ConnectionError) connection not available and request was dropped from queue after 2733ms. You can configure how long re...
New
For example for a current url like
http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2,
I would like to get:
...
New
Hello, I get Persian date from my client and convert it to normal calendar like this:
def jalali_string_to_miladi_english_number(persi...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
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
Other popular topics
Hello, how can I check the Phoenix version ?
Thanks !
New
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this:
...
New
Hey,
Just curious what are the main benefits of Elixir compared to Clojure?
When is Elixir more useful than Clojure and vice versa?
Th...
New
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors:
[WARN] - (starship::utils): Executing command ...
New
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
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









