Changing date format date -d '180617' +%d-%m-%Y in Shell Changing date format date -d '180617' +%d-%m-%Y in Shell shell shell

Changing date format date -d '180617' +%d-%m-%Y in Shell


You have misunderstood the option format in date command.

date -d "format" should be as below:

date -d "yymmdd"

That is why , Your date becomes year number in your format.

date -d '170618' +%d-%m-%y

This gives you the right output.

As far you couldn't change the format in your script,said in comments, here is your needed code.

date -d `date +%d%m%y%H%M%S | cut -c1-6| sed -E "s/(..)(..)(..)/\3\2\1/g"` +%d-%m-%y

This would change the format after your possibilities..

18-06-17