954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Time Comparison

Hi Frendz,
I have two text fields 'from time' and 'to time'. The time format of the two text fields are 11:30 am 01:30 pm. I want to give alert message in javascript when the users enter the to time less than the from time.

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 
<html>
 
 
<script language="javascript"> 
 
	function validate(dt1,dt2)
	{
		
		var jdt1=Date.parse('20 Aug 2000 '+dt1);
		var jdt2=Date.parse('20 Aug 2000 '+dt2);
		alert(jdt1);
		if(jdt1==NaN)
		{
			alert('invalid start time');
			return false;
		}
		if(jdt2==NaN)
		{
			alert('invalid end time');
			return false;
		}
	  	if (jdt1>jdt2)
		{
			alert('start is greater');
		}
		else
		{
			alert('start is less equal');
		}
	
		
	}
	
</script>
 
<body>
<div>
 
 
<form name=frm id=frm action=temp.php method="get" accept="text/csv">
<P>&nbsp;</P>
start <INPUT id=txt1 name=txt1 value='10:30:05 am'>&nbsp; 
end <INPUT id=txt2 name=txt2  value='10:40:05 am'>&nbsp; 
<input type=button value=ok id=button2 name=button2 onclick ='validate(document.frm.txt1.value,document.frm.txt2.value)'>&nbsp;&nbsp; 
 </P>
</form></div>
<script language='javascript'> 
</script>
<div id="txtHint">&nbsp;
</div>
<P></P>
 
</body>
</html>
urtrivedi
Nearly a Posting Virtuoso
1,306 posts since Dec 2008
Reputation Points: 257
Solved Threads: 270
 

Thanks Urtrivedi. My problem is solved.

Karthik_pranas
Posting Pro
564 posts since Feb 2011
Reputation Points: 96
Solved Threads: 97
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: