thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

bash built-in date

β€’ 48 words β€’ 1 min β€’ updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

To format dates GNU date is often used:

shell
$ date '+%Y-%m-%d'
2024-10-07

It turns out bash (>=4.2) has this feature built-in as part of printf:

shell
$ printf '%(%Y-%m-%d)T\n'
2024-10-07

It does not work on zsh though:

shell
% printf '%(%Y-%m-%d)T\n'

printf: %(: invalid directive

Source: https://blog.marco.ninja/notes/technology/linux/working-with-dates-in-bash-and-other-shells/