Skip to content

Instantly share code, notes, and snippets.

@correl
Last active June 18, 2018 15:28
Show Gist options
  • Save correl/e190fa9bfdc84717cd5acc7bba82f11b to your computer and use it in GitHub Desktop.
Save correl/e190fa9bfdc84717cd5acc7bba82f11b to your computer and use it in GitHub Desktop.
Month difference in an org table
#+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