0

The code below is giving me trouble. When I select July 1st 11:00pm for fromDate, result 3 is being set to Thu Jun 02 2011 11:52:26. I check the values of fromDate and toDate in chrome and they seem fine but result 3 is getting set to a wacky date. Any solutions?

function(value, element, params) {
            fromDate = new Date(startDate.val());
            toDate = new Date(endDate.val());
            result1 = this.optional(element);
            result2 = fromDate <= toDate;
            result3 = new Date();
            result3.setDate(fromDate.getDate()+1);
            result5 = (toDate.getDate()+0);
            result4 = (fromDate.getDate()+1)>(toDate.getDate()+0);
            return result1 || (result2 && result4);
        }
1
  • Can you include more information? It's not not totally clear what is the problem and what is being asked... Commented Jun 10, 2011 at 16:17

1 Answer 1

1

result3.setDate(fromDate.getDate()+1) only sets the day of the month of your Date object. Since result3 creates a new Date object, this means that result3 is not having its time set correctly.

If you want to set result3 to fromDate plus one day, you'll have to do something like this:

var DAY_IN_MILLISECONDS = 1000 * 60 * 60 * 24;
result3 = new Date(fromDate + DAY_IN_MILLISECONDS);

However, since I'm not sure what your variables represent, it's hard to diagnose.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.