Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

last date of month 1

Status
Not open for further replies.
Sep 28, 2002
20
0
0
IN
How can get last date of particular date's month ?
e.g. If I entered 2 feb 2004 , it must return 29 .
Pl. help ? Is there any command to do so for SUN 5.6 ?
 
sachinss1978,

There's probably an easeir way, but this works...

#!/usr/bin/ksh

M=$1
Y=$2

cal $M $Y | tail -2 | grep -v ^$ | awk '{print $NF}'

You could put it in a script called last_day or whatever you would like and run it like this:

last_day 02 2004

And it would return:
29

Hope this helps.

John

 
After doing some testing, I noticed that it didn't work for May 2004, so here is the modified code:

#!/usr/bin/ksh

M=$1
Y=$2

cal $M $Y | awk 'length>0 {print $NF}' | tail -1


John
 
Thank you .. Its working fine.
Is there any command available ?
 
Make your own using the above script and call it with the two parameters.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top