From 38e9f27b05c223f17fcde06a7ee6573c7a0020ce Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Tue, 28 Jun 2016 15:52:41 -0500 Subject: [PATCH] Add Create A Date With The Date Sigil as an elixir til --- README.md | 3 ++- elixir/create-a-date-with-the-date-sigil.md | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 elixir/create-a-date-with-the-date-sigil.md diff --git a/README.md b/README.md index 26f39d8..97c6511 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ variety of languages and technologies. These are things that don't really warrant a full blog post. These are mostly things I learn by pairing with smart people at [Hashrocket](http://hashrocket.com/). -_439 TILs and counting..._ +_440 TILs and counting..._ --- @@ -82,6 +82,7 @@ _439 TILs and counting..._ ### Elixir - [Append To A Keyword List](elixir/append-to-a-keyword-list.md) +- [Create A Date With The Date Sigil](elixir/create-a-date-with-the-date-sigil.md) - [Execute Raw SQL In An Ecto Migration](elixir/execute-raw-sql-in-an-ecto-migration.md) - [Expose Internal Representation](elixir/expose-internal-representation.md) - [List Functions For A Module](elixir/list-functions-for-a-module.md) diff --git a/elixir/create-a-date-with-the-date-sigil.md b/elixir/create-a-date-with-the-date-sigil.md new file mode 100644 index 0000000..ed6827b --- /dev/null +++ b/elixir/create-a-date-with-the-date-sigil.md @@ -0,0 +1,17 @@ +# Create A Date With The Date Sigil + +Elixir 1.3 introduced a new sigil for creating dates, `~D`. It works in the +same way as Date's +[`new/3`](http://elixir-lang.org/docs/stable/elixir/Date.html#new/3) +function producing the Date struct with each of the date parts. + +```elixir +> ~D[2016-01-01] +~D[2016-01-01] +iex(7)> ~D[2016-01-01].year +2016 +iex(8)> ~D[2016-01-01].month +1 +iex(9)> ~D[2016-01-01].day +1 +```