1825719 Members
3071 Online
109686 Solutions
New Discussion

Date Question

 
SOLVED
Go to solution
Vasudevan MV
Frequent Advisor

Date Question

Hello all,

I have written a script to generate a report for the given start date and end date. In the script I need to check whether the start date is Monday or not. Is there any readymade function or commands in shell script?.

Thanks in advance

Vasu
5 REPLIES 5
Corthouts Carlo
Valued Contributor

Re: Date Question

hi,

Try with "date +%A".
This will return the full
weekday in characters.

Patrick Wallek
Honored Contributor

Re: Date Question

# date +%a
Thu

# date +%A
Thursday

In your script you could do:

day = `date +%a`

Then if day = Mon do whatever you need to do.
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Date Question

Hi:

As usual my universal date hammer, caljd.sh, does this well. The -w option returns the day of the week, 0 - Sun; 6 - Sat.

For a given date:
DATE="3 4 2002" # March 4, 2002
WKDAY=$(caljd.sh -w ${DATE})

For today:
WKDAY=$(caljd.sh -w)

In either case,
if [ ${WKDAY} -eq 1 ]
then
echo "Monday Stuff"
else
echo "Not Monday Stuff"
fi

You can do a caljd.sh -u for full usage. P.S. It even knows about holidays.


Regards, Clay
If it ain't broke, I can fix that.
Vasudevan MV
Frequent Advisor

Re: Date Question

Hi,

Thanks everyone for ur suggestions. I wanted to assign points but the option was disabled. I don't know how to assign the points now.

Clay

Your code is working fine and thats what I need.

Vasu
Vasudevan MV
Frequent Advisor

Re: Date Question

Hey I have assigned points now.

Vasu