How to generate filename containing date & time on the command line

The following snippet is useful for backups to generate a unique yet sortable filename containing both date and time:

mysqldump-$(date +%F_%H-%M-%S).sql

This generates filenames like

mysqldump-2022-03-26_20-47-01.sql

which are compatible with both Windows and Linux as they don’t contain special characters likeĀ :