Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

date command on Mac OS

I would like to use the date command on a Mac to find out the day corresponding to a certain date.

On Debian the command below works:

date --date "Jul 20 1999" +%A

But the same command does not work when I use Mac's terminal.

What can be an alternative to achieve the output of the above command on a Mac?

like image 557
Mohammad Jumah Avatar asked Dec 06 '15 20:12

Mohammad Jumah


1 Answers

This works:

date -j -vJulm -v20d -v1999y '+%A'

According to the OSX date manual page::

-v
Adjust (i.e., take the current date and display the result of the adjustment; not actually set the date) the second, minute, hour, month day, week day, month or year according to val. If val is preceded with a plus or minus sign, the date is adjusted forwards or backwards according to the remaining string, otherwise the relevant part of the date is set. The date can be adjusted as many times as required using these flags.

like image 96
Thomas Dickey Avatar answered Oct 19 '22 16:10

Thomas Dickey