What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14481 |  Welcome, Guest!   Register  Login
 Home > Code Snippets > JavaScript > Validation for different formats of dates according to todays date in javascript. ...
Maneel

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

 Code Snippet posted by: Maneel | Posted on: 7/30/2012 | Category: JavaScript Codes | Views: 547 | Status: [Member] | Points: 40 | Alert Moderator   


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
Found interesting? Add this to:


>> Write Response - Respond to this post and get points

More codes snippets

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 6:15:28 PM