Last active
June 18, 2018 15:28
-
-
Save correl/e190fa9bfdc84717cd5acc7bba82f11b to your computer and use it in GitHub Desktop.
Month difference in an org table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#+BEGIN_SRC emacs-lisp | |
(defun months-diff (a b) | |
(let* ((date-a (mapcar #'string-to-number (split-string a "-"))) | |
(date-b (mapcar #'string-to-number (split-string b "-"))) | |
(months-a (+ (* 12 (car date-a)) (cadr date-a))) | |
(months-b (+ (* 12 (car date-a)) (cadr date-b)))) | |
(+ | |
(- months-a months-b) | |
(if (< (caddr date-a) (caddr date-b)) -1 0)))) | |
#+END_SRC | |
#+RESULTS: | |
: months-diff | |
| Foo | 2018-03-01 | 6 | | |
| Bar | 2018-02-01 | 7 | | |
#+TBLFM: $3='(months-diff "2017-09-01" $2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment