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


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