• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to get date of next anniversary ?

 
Sylvia Wang
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all
is there any easy way( no complex conversion) to get a new Date of the next anniversary of a given Date ?
e.g. from 12/13/2001 => 12/13/2002
Thanks.
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sylvia Wang:
Hi, all
is there any easy way( no complex conversion) to get a new Date of the next anniversary of a given Date ?
e.g. from 12/13/2001 => 12/13/2002
Thanks.


Jamie
 
Sylvia Wang
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it's great !
Thank you !
 
Sylvia Wang
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, found a small problem,
the Date type returned by getTime() is java.util.Date
tried to downcast to java.sql.Date by
java.sql.Date = (java.sql.Date)util_date;
but doesn't work. why ?
Thxs.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this...
java.util.Date today = new java.util.Date();
java.sql.Date td = new java.sql.Date(today.getTime());

------------------
Bosun
SCJP for the Java� 2 Platform
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is a neat and quick way to convert it in your code:

the first getTime() returns a Date object, the second getTime() is on the returned Date object which returns a long...which is used in the constructor of java.sql.Date.
Jamie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic