File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 58


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
how to Calculate fiscal month if start year and end date is given using JAVA
How to get weeks for a particular year with Calendar object
Java Date and time classes - Format AM_PM field
select boxes depends on other select box
Get Sum of column and the retrive the data month wise.