Kapsh Kapsh - 5 months ago 35
Bash Question

YYYY-MM-DD format date in shell script

I tried using

$(date)
in my bash shell script, however I want the date in YYYY-MM-DD format. How do I get this?

Answer

In Bash:

get year-month-day from date

DATE=`date +%Y-%m-%d`

get year-month-day hour:minute:second from date

DATE=`date +%Y-%m-%d:%H:%M:%S`


Other available date formats can be viewed from the man pages:

$man date