Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 5 down vote accepted

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
share|improve this answer
    
Thanks.................. –  Rajeev May 9 '11 at 16:33

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.

share|improve this answer
    
Thanks.......... –  Rajeev May 9 '11 at 16:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.