Kapsh Kapsh - 8 months ago 51
Bash Question

YYYY-MM-DD format date in shell script

I tried using

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


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