Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends....plese give solution for this

i have taken same function names for two textfeild.

and and get the date values and find no of months fine but i put validation for From date and Todate plz help me..

my code is here


JavaScript
<script>
function pamount_change()
{

var date1 = document.getElementById('pamount6').value;
  var date2 = document.getElementById('pamount7').value;
  date1 = date1.split("-");
  date2 = date2.split("-");
  var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
  var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
  var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));
  alert(daysApart);
 //document.getElementById("pmonths").value=_Diff;
        }

</script>

   <input type="text"  name="pamount6" class="datepicker" onchange="pamount_change();" onkeyup="acceptnumspecial(this,'pamount6')"  id="pamount6"  /></td>
    <input type="text"  name="pamount6" class="datepicker" onchange="pamount_change();" onkeyup="acceptnumspecial(this,'pamount7')"  id="pamount7"  /></td>





thaks ®ards

Mallesh[Email-id Deleted]
Posted
Updated 15-Jan-13 2:43am
v3
Comments
Abhishek Pant 15-Jan-13 8:45am    
Do you really want spams in your email's inbox? Please note that do not post your emailid here.

var daysApart = Math.abs(Math.round((sDate-eDate)/86400000));

I recommend doing the subtraction and checking for a negative value first, then performing the other operations.
 
Share this answer
 
What do you want to achieve? If you want to compare dates, you have already done the required bit.
JavaScript
var sDate = new Date(date1[0]+"/"+date1[1]+"/"+date1[2]);
var eDate = new Date(date2[0]+"/"+date2[1]+"/"+date2[2]);
if(sDate>eDate)
alert('start date is greater than end date');
else
if(eDate>sDate)
alert('end date is greater than start date');
else
alert('both dates are equal');
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900