I will set one date variable(Say \'08-JUN-2011\') and I want to do some calculations based on that date namely,
1. Have to get the first day of the given day\'s month.
This is going to be convoluted in a shell script. You are better off using Date::Manip in perl, or something similar in another full-featured language. However, I can think of some ways to do this with the date command. First of all, you can use a --date parameter to set a starting point for date, like so:
$ date --date='08-JUN-2011' Wed Jun 8 00:00:00 EDT 2011
You can get the previous date like this:
$ date --date='08-JUN-2011 -1 days' Tue Jun 7 00:00:00 EDT 2011
For the last day of the month, I would just walking back from 31 until date does not fail. You can check $? for that
$ date --date='31-JUN-2011';echo $? date: invalid date `31-JUN-2011' 1 $ date --date='30-JUN-2011';echo $? Thu Jun 30 00:00:00 EDT 2011 0
For the first day of the month...that is usually 01 :)