Kapsh Kapsh - 2 years ago 197
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?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download