File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases 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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Calendar dates" Watch "Calendar dates" New topic

Calendar dates

raj chopra
Ranch Hand

Joined: Apr 09, 2012
Posts: 64

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.

raj chopra
Shashank Gollapudi
Ranch Hand

Joined: Jan 19, 2012
Posts: 33
Calendar c1= Calendar.getInstance();
c1.set(Calendar.DAY_OF_MONTH, 1);
c1.set(Calendar.YEAR,c1.get(Calendar.YEAR)-1 );

Please let me know if this meets your requirement
subject: Calendar dates
It's not a secret anymore!