I am developing struts appication. I am displaying date in index.jsp as mm/dd/yyyy format. User can enter date in the same format. After Validation i am receiving date in mm/dd/yyyy from user. Now from mm/dd/yyyy i want to capture only month and year as i want to show data from mm/01/yyyy mm/dd/yyyy. Example if user input 10/12/2005 then i need to show data from 10/01/2005 to 10/12/2005 So i want to capture montha dn year what user enters. Can anyone guide me how to get month and year from user input date.
If you've been through validation and you're confident that the string is in mm/dd/yyyy format you could substring the fields or use String.split() to break the string into an array.
It's more "objecty" though to use SimpleDateFormat to parse the string into a Date object, then set the day-of-month field to 01, then use the date format again to convert it to a new string.
I don't know your comfort level with exploring either of those solutions. Let us know if you've used SimpleDateFormat or can figure it out from the JavaDoc. Put together a code fragment that shows us how far you get and where you get stuck - if you do.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi