Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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: 60759
189
  • 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: 21502
96
Chrome Eclipse IDE Java Spring Ubuntu VI Editor 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: 16084
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: 60759
189
  • 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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!