aspose 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 Spring in Action this week in the Spring 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: 39409
    
  28
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: 19720
    
  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: 14269
    
  21

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 8 API documentation
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: 39409
    
  28
why can't the rest of the Oracle/Sun documentation be that easy to understand?
 
Don't get me started about those stupid light bulbs.
 
subject: How to minus 45 days from from the current sysdate