help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The wild and weird world of Emacs Lisp date/time arithmetic


From: Teemu Likonen
Subject: Re: The wild and weird world of Emacs Lisp date/time arithmetic
Date: Thu, 17 Dec 2020 21:47:27 +0200

* 2020-12-17 09:57:18-06, Skip Montanaro wrote:

> I want to write a function to add a day [...]

> I have no problem plucking the time out of the buffer or decoding the
> string. I'm having trouble converting back to string form after
> parsing and doing the arithmetic.

You can do it with a function like this:


    (defun my-add-one-day (date-string)
      (let ((decoded (decoded-time-add (parse-time-string date-string)
                                       (make-decoded-time :day 1))))
        (format "%04d-%02d-%02d"
                (nth 5 decoded)
                (nth 4 decoded)
                (nth 3 decoded))))


(my-add-one-day "2020-12-31") ;=> "2021-01-01"

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]