| 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: 32611
|
|
|
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: 371
|
|
|
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: 19216
|
|
And of course, subtracting 45 days is the same as adding -45 days
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
|
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: 371
|
|
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: 32611
|
|
|
why can't the rest of the Oracle/Sun documentation be that easy to understand?
|
 |
 |
|
|
subject: How to minus 45 days from from the current sysdate
|
|
|