JavaScript Validation: Date Range

This quick post shows how to validate two date fields by comparing their values. When there is two date fields in a page like From Date & To Date , then generally arises a requirement to show a message that From Date can not be greater than To Date or, something like that. This is required when the user inputs a greater date in  the From Date field than To Date.


Here I have taken two TextBox for inputting dates named- txtFromDate & txtToDate

var FromDt = document.getElementById("<%=txtFromDate.ClientID %>").value;
var ToDt = document.getElementById("<%=txtToDate.ClientID %>").value;

if (Date.parse(FromDt.trim()) > Date.parse(ToDt.trim())) {
    alert("Please check date range!\nFrom Date cannot be greater than To Date!")
    return false;


3 thoughts on “JavaScript Validation: Date Range

  1. Good site – I tend to have the same opinion with nearly all of what you wrote. I would love to see more posts on this. I will bookmark and come back.

  2. Hello webmaster. I came to your “JavaScript Validation: Date Range Suvendu's Blog” page via Google but it was hard to find as you were not on the first page of search results. I see you could have more traffic because there are not many comments on your site yet. I have found a website which offers to dramatically increase your rankings and traffic to your website: They managed to get close to 1000 visitors/day using their services, you could also get lot more targeted traffic from search engines than you have now. I used their services and got significantly more traffic to my site. Hope this helps 🙂 Take care. Annette

  3. Hello i am kavin, its my first occasion to commenting anyplace, when
    i read this post i thought i could also create comment due
    to this sensible article.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s