CoderZone.org

Category: >> JavaScript >> Check if a date is in the past Bookmark and Share

<< lastnext >>

Snippet Name: Check if a date is in the past

Description: This javascript snippet checks that a user-supplied date is not in the past. That is, the date the user entered must be equal to or greater than the current date.

Also see:
» Accept Payments with Google Checko...
» Validate file extensions in upload...
» Get Easter Date for any year in Ja...
» Check for a Valid Email Address (V...
» Check if current session is using ...
» Check For A Valid Email Address
» Check If A Directory Allows File C...
» Another Good Email Validator
» Validate A URL
» Check whether a date belongs to a ...
» Checking Server Status with PHP
» Check for duplicates and delete du...
» MKDIR with error checking
» Check Constraint - Create
» Check email address
» INSERT WITH CHECK OPTION
» Validate credit card numbers
» Check number of characters in a ra...
» Check if an image exists (GD)
» Check if a file exists
» Toggle All Checkboxes on or off
» Check if array is associative
» Check syntax of multiple PHP files...
» Deferring Constraint Checking
» Count checkboxes
» Check or Uncheck all Checkboxes
» Check radio button selection
» Calculate time difference between ...
» Constraint Checks

Comment: (none)

Author:
Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: December 19th, 2010

// The input for the date in this case is assembled from 
// 3 separate fields (day, month, and year) but could just 
// as  easily be taken from a single form field. The date 
// format to be checked is 'yyyy/mm/dd'.
 
 
function checkdate(){
	var sendDate = document.getElementById('send_year').value + '/' + document.getElementById('send_month').value + '/' + document.getElementById('send_day').value;
	sendDate = new Date(Date.parse(sendDate.replace(/-/g,' ')))
	today = new Date();
	today.setHours(0,0,0,0)
	if (sendDate < today) {
		alert('The  date can\'t be in the past. Please pick another date.');
		return false;
	} 
}
 
Add a comment 
ranadheerDec 24th, 2014 8:42am
you can check this using the following jquery code

var EnteredDate = document.getElementById("txtdate").value; //for javascript

var EnteredDate = $("#txtdate").val(); // For JQuery

var date = EnteredDate.substring(0, 2);
var month = EnteredDate.substring(3, 5);
var year = EnteredDate.substring(6, 10);

var myDate = new Date(year, month - 1, date);

var today = new Date();

if (myDate today)
alert("Entered date is greater than today's date ");

else
alert("Entered date is less than today's date ");

for more info refer this : http://coding-issues.blogspot.in/2013/08/check-given-date-greater-than-current.html
© coderzone.org | users online: 12