MacOs is not the same family of UNIX as Linux, so options for commands can be different.
By installing coreutils on MacOS, we can use the GNU/Linux date very easily as well.
brew install coreutils
Then we can use GNU/Linux date with this command gdate instead of date on MacOS.
Here is my example by using gdate to calculate the date on MacOS.
MONDAY=$(gdate -d 'last monday' '+%d.%m.%Y')
FRIDAY=$(gdate -d 'this Friday' '+%d.%m.%Y')
It will return the calculated date as the following(current date as I tested them: 08:05AM 31.05.2022):
echo $MONDAY
## 30.05.2022
ECHO $FRIDAY
## 03.06.2022
Top comments (0)