Is there a function to parse the text around the cursor and return the date if found?

E.g., if I'm in a buffer with the cursor in the middle of this text:

2015-12-01 First day of new exercise program
2016-01-08 Hit a milestone: ran a 7-minute-mile

and I want to use emacs to parse the dates and tell me the elapsed time between them, is there a function to help me do that? Ideally it would handle full ISO timestamps also, e.g.


and of course other date formats. Yeah - I know - it gets tricky, might need some hinting on formats, etc....

It looks like date-to-time can parse ISO strings, and parse-time-string can parse some formats, but not ISO. But are there any functions to pick the right text from around the cursor?

See e.g. Emacs Lisp: Parsing Date Time

  • 2
    See the the library date-at-point: github.com/alezost/date-at-point.el With that library (although I have never used it), you can probably do something like: (save-excursion (goto (point-at-bol)) [date-at-point applicable function]) and something similar for the next line, and then compare and contrast, etc. -- and of course, do your conversions along the way. – lawlist Jan 8 '16 at 15:36
  • Cool. It looks like the thing-at-point library and that tiny bit of code is the sort of thing I'm looking for, and could be extended to include timestamps..... – nealmcb Jan 8 '16 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.