Validation for different formats of dates according to todays date in javascript.

Maneel
Posted by Maneel under JavaScript category on | Points: 40 | Views : 2071
Introduction :


Basically in JavaScript we don't get all the options like in server side code. The common requirement for everyone is date formats according to their requirement.

Converting Date format using javascript :


In this article i am going to explain about different types of date formats in JavaScript and validations for the dates according to today date or adding some days to the today's date or whatever the date we need to check.

       
var dt = new Date();
var TodayDate = dt.format("MM/dd/yyyy");
TodayDate.setDate(TodayDate.getDate() + 30);


Here in this case the variable "dt" will get the todays date in according to the system format. After that in variable "TodayDate" we are getting today's date in "MM/dd/yyyy" format. For the obtained date i am adding 30 days. so now we will get the exact date after 30 days means one month here in today's date variable.

For example the date which we have obtained in server side code will be stored as a string in hidden field. This string value can be converted to date and can be validated now.


var TodayDate = dt.format("MM/dd/yyyy");
var HiddenFielddate = document.getElementById("hdDate").value;
if (TodayDate > HiddenFielddate) {
alert('Your message here.');
}


You can check different types of date format here :
http://yash-maneel.blogspot.in/2012/05/convert-date-format-in-javascript.html

Comments or Responses

Login to post response