How to print date in MM/DD/YYYY formate in unix?

Viewed 117

I'm new to unix and I'm trying to run print the date using:

echo "Purchase date: `date`"

but I keep getting the date in the format

Purchase date: Fri Oct 2 12:21:26 EDT 2020

but I'm trying to get it in the format of MM/DD/YYYY

1 Answers

A quick google search will show you lots of options but I believe you want something like: ~$ date +%m/%d/%Y

~$ 10/02/2020

%[a-z] represents formatting options.

  • %m - month (01..12)
  • %d - day of month
  • %Y - Full Year
  • '/' - Delimiter

You can see all of the date formatting options by using the help command: ~$ date --help

Related