Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7367979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:36:22+00:00 2026-05-29T03:36:22+00:00

i saw this example : Validate that end date is greater than start date

  • 0

i saw this example : Validate that end date is greater than start date with jQuery

talking about the validation of end date greater than start, date format for my input are always mm/yyyy, so it’s not working for me if :
start date > 122000
end date > 012002

I think i have to split my date, to just check on yyyy, if is greater or not, but didn’t know how to resolve it … here is my code ( i want always to say that if i have not 7 characters in my input to don’t pass form submit :

HTML

<input type="text" id="starddate" />
<input type="text" id="enddate" />
<div id="msg"></div>
<input type="submit" id="submit" />

JS

jQuery.validator.addMethod("greaterThan", 
function(value, element, params) {

    if (!/Invalid|NaN/.test(new Date(value))) {
        return new Date(value) > new Date($(params).val());
    }

    return isNaN(value) && isNaN($(params).val()) 
        || (parseFloat(value) > parseFloat($(params).val())); 
},'Must be greater than {0}.');

$("#enddate").rules('add', { greaterThan: "#startdate" });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T03:36:23+00:00Added an answer on May 29, 2026 at 3:36 am

    If your date values are strings are in the form mm/yyyy, then you can’t use new Date(value) to create a Date object for them — that’s not a format that the Date constructor is documented as accepting (and until recently, it wasn’t documented to accept anything at all except whatever the output of toString was, which was also up to the implementation to decide).

    But the problem’s not difficult: Given dateA and dateB which are strings in that format:

    // Assumes the format mm/yyyy (not mmyyyy, which your example values seem to be in)
    var compareA, compareB;
    compareA = dateA.substring(3) + dateA.substring(0, 2);
    compareB = dateB.substring(3) + dateB.substring(0, 2);
    if (compareA > compareB) {
        // The date represented by `dateA` is later than the date
        // represented by `dateB`
    }
    

    or less clearly

    if (dateA.substring(3) + dateA.substring(0, 2) > dateB.substring(3) + dateB.substring(0, 2)) {
        // ...
    }
    

    E.g., you can just compare strings if you move the year before the month, because the string "200012" is < the string "200201".

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery bassistance validation and need to verify that a start date
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
Saw this example on the jQuery examples page for Ajax: var xmlDocument = [create
I saw this example about storing login information in cookie. http://eisabainyo.net/weblog/2009/02/20/store-login-information-in-cookie-using-jquery/ Tried it, but
I'm looking at the Plugin Authoring article at http://docs.jquery.com/Plugins/Authoring and saw this example in
I saw this same question for VIM and it has been something that I
I saw this question asked about C# I would like an answer for PHP.
I was going over C++0x. As i looked at tuple I saw this example.
Reading a post about redis I saw this word: REPL . Can someone tell
I saw this example in php manual page http://www.php.net/manual/en/session.examples.php The example will create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.