[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] babel and computing a number of months
From: |
Alan Schmitt |
Subject: |
Re: [O] babel and computing a number of months |
Date: |
Mon, 02 Jun 2014 14:06:10 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (darwin) |
On 2014-06-02 10:13, Alexis <address@hidden> writes:
> Alan Schmitt writes:
>
>> I need to work with dates for some code/scripts I'm writing in a
>> document making heavy usage of source blocks and babel evaluation. The
>> good news is that I have access to many programming languages, so the
>> bad news is I don't know which one to choose. The problem I want to
>> solve is the following: I want to compute the number of months between
>> march 1st, 2014, and the beginning of the current month (so right now
>> it's 3, but on may 31st it was 2). Is there an easy way to do it in a
>> babel supported language?
>
> How about Perl with either DateTime::Moonpig:
>
> https://metacpan.org/pod/DateTime::Moonpig
>
> or Time::Piece:
>
> https://metacpan.org/pod/Time::Piece
Thank you for the suggestion. I finally did a very hackish simple
solution:
#+begin_src emacs-lisp
(defun nbmonthssince (year month)
(let* ((tm (decode-time))
(cmonth (nth 4 tm))
(cyear (nth 5 tm)))
(+ (* 12 (- cyear year)) (- cmonth month))))
#+end_src
Alan