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 6651611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:01:57+00:00 2026-05-26T01:01:57+00:00

Sometime back i had asked question in SO as to how to validate startdate

  • 0

Sometime back i had asked question in SO as to how to validate startdate < enddate.

The JS that i had written is as below;

function DateValidation(startDate, endDate) {
                if (startDate != ' ' && endDate != ' ') 
                {
                    var stdate = Date.parse(startDate);
                    var enddate = Date.parse(endDate);
                    if (stdate > enddate) 
                    {
                        alert('Start date cannot be greater than end date!');
                        return false;
                    }
                    else 
                {
                    return true;
                }
               }
            }

The function gets called on the click of the submit button. It is register as;

OnClientClick="javascript: return DateValidation(window.document.getElementById('txtStartDate').value,window.document.getElementById('txtEndDate').value);"

Now assume that start date is October 4 2011 (04/10/2011) and end date is December 2 2011 (02/12/2011). In this case the alert should NOT get fired but it still gets fired up (because 04 > 02).

What mistake am i making here?

  • 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-26T01:01:58+00:00Added an answer on May 26, 2026 at 1:01 am

    Your startDate & endDate parameters should be in mm/dd/yyyy format. But you provided them as dd/mm/yyyy format, so the unexpected thing occured.

    I’ve faced this kinda probs B4. If your website’s clients are all about to type in date time in format “dd/mm/yyyy”, so you need a “correctDate()” function to replace date part with month part in the input-date-string.

    The function may look like this :

    function correctDate(D){
           var D=D.split('/');
           return D[1]+'/'+D[0]+'/'+D[2]
    }
    //input :  2/10/2011 , output :  10/2/2011
    

    And in the DateValidation() function, you can use it like this:

    ....
          var stdate = Date.parse( correctDate(startDate) );
          var enddate = Date.parse( correctDate(endDate) );
          if (stdate > enddate){
    ....
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sorry for this not being a real question, but Sometime back i remember seeing
I had telephone interview question yesterday. The interviewer asked me if I had faced
A while back i had a question about why my socket sometimes received only
Some time back i had installed MySQL on Windows. Firstly,I got to learn that
I had installed QT for some project sometime back but don't use it now(may
I am using ubunutu natty narwhal.I had installed ruby,rails,rvm etc.. sometime back and everything
I ran across a small framework some time back that someone put together for
This question has in the back of my mind for some time, sorry if
Sometime I see many application such as msn, windows media player etc that are
This may be a dumb question, and based on the fact that googling has

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.