File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes How to minus 45 days from from the current sysdate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to minus 45 days from from the current sysdate" Watch "How to minus 45 days from from the current sysdate" New topic
Author

How to minus 45 days from from the current sysdate

Ravi Kiran Va
Ranch Hand

Joined: Apr 18, 2009
Posts: 2234

Hi ,

I have system Date Passed to the Java File , please Could anybody please tell me how can we minus 45 days from the current sysdate ??


Save India From Corruption - Anna Hazare.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
Have you tried any of the methods in the Calendar class?
rob michael
Greenhorn

Joined: May 22, 2011
Posts: 27
Campbell is right - you should use the Calendar class.

Something like this should do the job (so you don't have to worry about the number of days in the month)




Have a look at my blog: http://automateddeveloper.blogspot.com/
Or even my Android Apps (website): http://www.mobile.thirdmindmedia.co.uk
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Calendar has an add method, no need to do manual calculation: java.util.Calendar#add(int, int).
rob michael
Greenhorn

Joined: May 22, 2011
Posts: 27
Cool, I didn't realise that was the case, thats good to know
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

And of course, subtracting 45 days is the same as adding -45 days


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14116
    
  16

Also, rob michael, your code won't work correctly when the year has 366 days.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Hauke Ingmar Schmidt
Rancher

Joined: Nov 18, 2008
Posts: 433
    
    2
Rob Spoor wrote:And of course, subtracting 45 days is the same as adding -45 days


At least the Javadoc is clear about this ^^.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38509
    
  23
why can't the rest of the Oracle/Sun documentation be that easy to understand?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to minus 45 days from from the current sysdate