Kapsh Kapsh - 9 months ago 57
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