HollowBastion HollowBastion - 1 year ago 95
Bash Question

Convert date string to a different format in bash

Getting the date in bash works something like this:

echo "Current date: $now"

It returns:

Current date: Mon Nov 28 11:34:55 NZDT 2016

I need to store the date in a variable where the date is in a format like this:


How can I convert the date format into the format I need?

Answer Source

You use any format with +%

date +%Y%m%d


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download