Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Date arithmetic in Erlang

I have a date in this format {Y,M,D}. Is there any good supporting libraries or, tricks I can use to simply, say subtract three months from this date without running into problem with invalid dates, leap years, etc.

My latest similar use is in MySql where you can type:

Select '2011-05-31' - Interval 3 Month;

which yields '2011-02-28'. I am not interested in how to write this library myself, that is what I would like to avoid.

like image 818
Magnus Kronqvist Avatar asked Jul 14 '11 15:07

Magnus Kronqvist


1 Answers

1> calendar:gregorian_days_to_date(calendar:date_to_gregorian_days({2011, 7, 14}) - 90).     
{2011,4,15}

http://www.erlang.org/doc/man/calendar.html

like image 182
Victor Moroz Avatar answered Nov 16 '22 02:11

Victor Moroz