The easiest way to get a date in YYYY-MM-DD is follows:
date -I
Output: 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-%d
Output: 2016-06-07, the same.
If you want to display also hours:minutes:second, let's do:
date +%Y-%m-%d:%H:%M:%S
Output: 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