The easiest way to get a date in YYYY-MM-DD is follows:
date -IOutput: 2016-06-07
The parameter āIā tells the date command, the ISO date format is required.
Of course, you can also use your own definition. %Y means year, %m means month, and %d means day:
date +%Y-%m-%dOutput: 2016-06-07, the same.
If you want to display also hours:minutes:second, let's do:
date +%Y-%m-%d:%H:%M:%SOutput: 2016-06-07:17:02:19
You fill the variable date as follows:
DATE=`date +%Y-%m-%d:%H:%M:%S`Here are some examples of format control:
Was this information helpful to you? You have the power to keep it alive.
Each donated ⬠will be spent on running and expanding this page about UNIX Shell.
We prepared for you video course Marian's BASH Video Training: Mastering Unix Shell, if you would like to get much more information.
Thank you. Marian Knezek