How can I get the previous month without using a package or library in elixir?
For example, if the current date is 2018-01-25
, I will get 2017-12-25
.
Or If the current date is 2018-03-31
, I will get 2018-02-28
(2018 is not a leap year)
How can I get the previous month without using a package or library in elixir?
For example, if the current date is 2018-01-25
, I will get 2017-12-25
.
Or If the current date is 2018-03-31
, I will get 2018-02-28
(2018 is not a leap year)
Use Timex library
The answer by @Sheharyar is almost there, the only difference you need to subtract the maximum of days in both months:
Works for all cases: