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-07It turns out bash (>=4.2) has this feature built-in as part of printf:
shell
$ printf '%(%Y-%m-%d)T\n'
2024-10-07It does not work on zsh though:
shell
% printf '%(%Y-%m-%d)T\n'
printf: %(: invalid directiveSource: https://blog.marco.ninja/notes/technology/linux/working-with-dates-in-bash-and-other-shells/