The functions you want are 'encode-time , 'format-time-string and 'decode-time . For proper documentation, either Ch f function-name , or you will receive documentation for this function, or the general elisp information pages can be found here: Ch im elisp RET m time conversion RET
Here is this snippet:
(defun my-insert-dates () "insert a bunch of dates" (interactive) (let* ((month 3) (day 1) (time (encode-time 1 1 0 day month 2009))) (while (= (nth 4 (decode-time time)) month) (insert (format-time-string "%D %a:\n" time)) (setq day (1+ day)) (setq time (encode-time 1 1 0 day month 2009)))))
I could not find how to determine the number of days in a given month (of course, you can hard code it, but then you have to deal with leap years). Fortunately, 'encode-time makes the whole addition for you, so if you give it the equivalent of February 31, it will return March 3 (within 28 days).
Trey jackson
source share