• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to minus 45 days from from the current sysdate  RSS feed

 
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 ??

 
Marshal
Posts: 57239
175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried any of the methods in the Calendar class?
 
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)


 
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
 
Sheriff
Posts: 21201
87
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
 
Java Cowboy
Sheriff
Posts: 16078
88
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
Marshal
Posts: 57239
175
  • 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?
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!