This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes Calendar dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Calendar dates" Watch "Calendar dates" New topic
Author

Calendar dates

raj chopra
Ranch Hand

Joined: Apr 09, 2012
Posts: 60


Hi All,
I am working on providing data from yesterday date to jan 1'st of last year sequentially.
eg : from 3/19/2013 to 1/1/2012
from 3/19/2013 to 1/1/2011 so on for 10 years.

From the below code i am getting the date exactly 1 year back date,like 3/19/2012. how can i get the subtration to be dne in such a way that i could get dates from jan 1'st onwards?

sample code:
Calendar cal = Calendar.getInstance();
cal.add(cal.YEAR, -1) ;

please help on this.

Reagrds,
raj chopra
Shashank Gollapudi
Ranch Hand

Joined: Jan 19, 2012
Posts: 33
Calendar c1= Calendar.getInstance();
System.out.println(c1.getTime());
c1.set(Calendar.DAY_OF_MONTH, 1);
c1.set(Calendar.MONTH,0);
c1.set(Calendar.YEAR,c1.get(Calendar.YEAR)-1 );
System.out.println(c1.getTime());

Please let me know if this meets your requirement
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar dates
 
Similar Threads
select boxes depends on other select box
How to get weeks for a particular year with Calendar object
how to Calculate fiscal month if start year and end date is given using JAVA
Java Date and time classes - Format AM_PM field
Get Sum of column and the retrive the data month wise.