2

In linux how to get the date of the first day of the week monday.

I know that date +"%u" gives the current day of the week from this how to get the date of the monday of that week

Rajeev
  • 251
  • 1
  • 4
  • 10

2 Answers2

5

The date command is very flexible about the input it will take from -d Try this

#!/bin/bash

if [ $(date +%u) -eq "1" ]
then
   date
else
   date -d "last monday"
fi
user9517
  • 115,471
  • 20
  • 215
  • 297
4

You can do

date --date="Monday"

to get the date of this Monday. You can also do

date --date="next Monday" 

to get the date of the next Monday. You can also use "last Monday" to get the date of the previous Monday.

Refer to the Man pages for more details.

Sameer
  • 4,118
  • 2
  • 17
  • 11