From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Schmitt Subject: Re: babel and computing a number of months Date: Mon, 02 Jun 2014 14:06:10 +0200 Message-ID: References: <87d2erpw3l.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrR0L-0007j5-BX for emacs-orgmode@gnu.org; Mon, 02 Jun 2014 08:06:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrR0D-0001RI-Jv for emacs-orgmode@gnu.org; Mon, 02 Jun 2014 08:06:17 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:62043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrR0D-0001Qo-ED for emacs-orgmode@gnu.org; Mon, 02 Jun 2014 08:06:09 -0400 In-Reply-To: <87d2erpw3l.fsf@gmail.com> (Alexis's message of "Mon, 02 Jun 2014 18:13:50 +1000") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Alexis Cc: emacs-orgmode On 2014-06-02 10:13, Alexis 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