How do you get the last day of the last month in csh?
Here is the code so far. The cal command below almost works if you execute it from the (FreeBSD sh) command line, but I'm having trouble escaping it properly to run within a script. By almost work, I mean it returns 31, when the last day of February 2010 is 28.
#!/bin/csh
set lastdayoflastmonth=`cal `date '+%m'` `date '+%Y'` | grep . | fmt -1 | tail -1`
echo $lastdayoflastmonth
To be clear:
If today is March 26th 2010, it should return the number 28, which is the last day of the February 2010.
If today is July 1st 2010, it should return the number 30, which is the last day of June 2010.
Update: working answer received from Joshua Smith in comments below: date -v31d -v-1m '+%d'
Thank you!