How can i format the date "01-SEP-2011" on "2011-09-01" format in shell script?
3 Answers
Try this:
$ date --date='01-SEP-2011' +%Y-%m-%d
2 Comments
Keith Thompson
That assumes you have the GNU coreutils version of the date command. If you're running bash, you probably do -- but it might not be installed by default on MacOS, for example. (I don't know whether bash is installed by default, but there's no non-GNU version of
bash; there are non-GNU versions of date.)Keith Thompson
date ... +%F also works (but I think +%Y-%m-%d is a bit more portable).