10 Replies Latest reply: Mar 3, 2009 10:56 AM by masijade RSS

    date compare in java

      I have Submitdate from db is String, Is that possible to found out some like Submitdate> 2 working Date ??
      I Google, in java have some compare before, and after , but How to found out 2 working date??
      Thak you!
        • 1. Re: date compare in java
          your question is not so clear..
          • 2. Re: date compare in java
            Use getDate, rather than getString. Use that date with Calendar, and add two days to it.
            • 3. Re: date compare in java
              [Use the force Luke|http://joda-time.sourceforge.net/].
              • 4. Re: date compare in java
                dear masijade,
                I change getDate and replace my getString,
                1) how to inital the date type in bean , Strinf we can use String ="";
                2) I looking for two workind Date, not just add two more date, or I can said if is not following is not Sunday, Saturday, not Holiday add two more date, I know how to do that, but how to handle the condition?? and decide when to add 3 or more
                thank you!
                • 5. Re: date compare in java
                  You're question is not clear due to bad grammar. Redo.

                  I realise the English isn't every-ones first language, and I myself have been know misspell the odd word (there and here), but you need to communicate at-least clearly enough to make those who can help understand your problem.

                  Try again dude.

                  Cheers. Keith.
                  • 6. Re: date compare in java
                    what I looking for is
                    1) in bean if the variable type is date, how should I initial it?
                    private String shipAward='';
                    private boolean receiveAll=false;
                    private Date submitDate=?;
                    2) checkDate=submitDate+two Working Date(not including Sunday and Saturday), is that possible
                    • 7. Re: date compare in java
                      1) i'm not sure if this is the "Bean" that you mean:
                       private String shipAward;
                      private boolean receiveAll;
                      private Date submitDate;
                           * @return the shipAward
                          public String getShipAward() {
                              return shipAward;
                           * @param shipAward the shipAward to set
                          public void setShipAward(String shipAward) {
                              this.shipAward = shipAward;
                           * @return the receiveAll
                          public boolean isReceiveAll() {
                              return receiveAll;
                           * @param receiveAll the receiveAll to set
                          public void setReceiveAll(boolean receiveAll) {
                              this.receiveAll = receiveAll;
                           * @return the submitDate
                          public Date getSubmitDate() {
                              return submitDate;
                           * @param submitDate the submitDate to set
                          public void setSubmitDate(Date submitDate) {
                              this.submitDate = submitDate;
                      2. ...
                      • 8. Re: date compare in java
                        Of course "Date d =". How would define a Date otherwise?

                        You have a Calendar and you need to add two days so add a day then check if that "new" date is either Saturday or sunday and, if so add another day. Where's the problem? If you need to exclude holidays as well, then the project is, of course, much more involved as you have to first determine when those holidays are, and that varies from country to country, province to province, state to state, and somtimes, even, from city to city. So good luck.
                        • 9. Re: date compare in java
                          thank you,
                          I would get back to your suggestion late. but How to check is Saturday or Sunday and for holiday I don't need to care about that much, I live in a small place.
                          • 10. Re: date compare in java
                            Check the API docs for Calendar, it's get(FIELD) method and the Calendar.SATURDAY and Calendar.SUNDAY constants.