1 Replies - 1197 Views - Last Post: 19 February 2012 - 06:51 PM

#1 praveenphp  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 20
  • Joined: 18-February 12

Date comparison in Javascript

Posted 19 February 2012 - 04:59 PM

is any one help to compare textfield date with current date in javascript??

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<script type="text/javascript">

function check(ff) 
{
  
  
var start = ff.from.value;

var end = new date();
alert(end);
var c_month = end.getMonth(); 
var c_day = end.getDate(); 
var c_year = end.getYear(); 
var fulldate = "" + c_month + "/" + c_day + "/" + c_year; 

alert(fulldate);

var stDate = new Date(start);
var enDate = new Date(fulldate);

var compDate = enDate - stDate;

if(compDate >= 0)
{
   alert("valid");
   return true;
 }
else
{
alert("Please Enter the correct date ");
return false;
}

}

</script>



</head>
<body>

  <form id="fff" name="fff" method="post" action="" style="">
  

<input type="text" name="from" id="from"/>
<input type="text" name="to" id="to"/>

<Input type="submit" name="insert" id="insert" value="Insert" onclick="return check(fff)"/>

</form>

</body>
</html>




This code is not working please any one tell me what is the mistake in this code.

This post has been edited by CTphpnwb: 19 February 2012 - 05:03 PM
Reason for edit:: Fixed code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Date comparison in Javascript

#2 JMRKER  Icon User is offline

  • D.I.C Addict

Reputation: 128
  • View blog
  • Posts: 826
  • Joined: 25-October 08

Re: Date comparison in Javascript

Posted 19 February 2012 - 06:51 PM

Part of your problem is line #15.
It should be: var end = new Date();

What is the purpose of this?
Your comments are a bit sparse!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1