# One-liner script that extracts a date from e.g. the clipboard

Got annoyed by copy and pasting dates and times from web articles, then having to clean the copied stuff up (some websites make it hard to select the date without activating a link, so you end up with the author name or whatever, too).

Here's a simple one-liner to clean things up, requiring any Ruby installed:

ruby -e 'require "date"; print Date.parse(ARGF.read).iso8601


It's simpler than my previous attempts with a Python script that parses date and time, e.g. from a Zettel ID.

This reads from standard input, looks for a date inside, then prints the 2021-08-11 form of the date.

Here's how you can test it by piping static text to the command:

echo "Nassim Taleb Jun 14, 2020 · 5 min read" | ruby -e 'require "date"; print Date.parse(ARGF.read).iso8601'


You can use Keyboard Maestro, too, for this:

Author at Zettelkasten.de • https://christiantietze.de/

• All these code snippets you periodically post to the interwebs are like little golden easter eggs for a non-programmer type such as myself. Makes me think I should switch back to learning ruby instead of banging my head on clojure like I am now. Anyway, thank you.

• @kohled If you know you need Clojure and other Lisp/Scheme-likes in the long run, it might be worth getting the "wizard book". That's a text-book teaching everything from fundamental principles. It's powerful, but requires work to understand and keep up with everything. Can be read for free online, too: https://mitpress.mit.edu/sites/default/files/sicp/index.html -- but it's hard enough to follow as-is, so I personally recommend hunting for the paperback, used.

Doesn't help with Clojure's tooling and library ecosystem, of course, but the language fundamentals should help a ton.

Author at Zettelkasten.de • https://christiantietze.de/

• @ctietze Sage counsel. It's vibrantly clear that the learning process will be best served by starting from fundamental principles. This book looks like a humbling challenge for me. I'll definitely need to brush up on my maths, but I've been needing to do that anyway.

Thank you for the suggestion. Very appropriate and helpful.