Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to minus 45 days from from the current sysdate

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??

 
Campbell Ritchie
Sheriff
Pie
Posts: 50239
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried any of the methods in the Calendar class?
 
rob michael
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)


 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Calendar has an add method, no need to do manual calculation: java.util.Calendar#add(int, int).
 
rob michael
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool, I didn't realise that was the case, thats good to know
 
Rob Spoor
Sheriff
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And of course, subtracting 45 days is the same as adding -45 days
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15485
43
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, rob michael, your code won't work correctly when the year has 366 days.
 
Hauke Ingmar Schmidt
Rancher
Posts: 436
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 50239
79
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why can't the rest of the Oracle/Sun documentation be that easy to understand?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic