• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

range

 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got 2 strings.
They will be in form for yyyymmdd
i.e. 20030802, 20030701
I want to do 2 things
1) make sure 1st one is earlier than 2nd one
2) they are not more than 30days apart.
Both will throw error.
Anyone can help?
thanks so much and really appreciated that.
 
Eric Fletcher
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since you know the format(and assuming it won't vary with input)I think I'd parse the date info out and create GregorianCalendar instances.
You can then use the boolean after() method(inherited from Calendar) to see if the one date is after another.
Then use the DAY_OF_YEAR fields in the different GregorianCalendar instances to determine if the dates are more than 30 days apart, i.e. do a subtraction and see if the difference > 30.
A lot of hoops to jump through, I realize, but I don't think there is any simple way to do this sort of thing with just String comparisons. Anybody?
HTH,
E
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like Eric's advice.
Jackie, what do you mean by "Both will throw error."? What did you try to do that caused an error?
 
Jackie Wang
Ranch Hand
Posts: 315
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks eric
what's GregorianCalendar?
To Dirk,
I think I will just return false or break out the method if any one of the rule violate. thansk!
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GregorianCalendar is a class in java.util
You can parse the String to Date using java.text.SimpleDateFormat
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic