•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 401,435 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,852 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 395 | Replies: 3 | Solved
![]() |
hi all,
i need a code for date comparision,my requirement is first we have to enter start date and when we enter end date it should check whether the date is greater than the start date or not if it is greater only it should alow otherwise it shoud alert........
for ex : if i entered start date as 20/07/2008
it shoudl accept the next dates like 21/07/2008 or later
but should not accept 19/07/2008
i hope u got my point.............
so pls. help me thanx in adv
i need a code for date comparision,my requirement is first we have to enter start date and when we enter end date it should check whether the date is greater than the start date or not if it is greater only it should alow otherwise it shoud alert........
for ex : if i entered start date as 20/07/2008
it shoudl accept the next dates like 21/07/2008 or later
but should not accept 19/07/2008
i hope u got my point.............
so pls. help me thanx in adv
var now = new Date();
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var user_dt=document.getElementById("ctl00_ContentPlaceHolder1_txtcanndate").value;
var dd=parseInt(user_dt.substring(0,2),10);
var mon=parseInt(user_dt.substring(3,5),10);
var yr=parseInt(user_dt.substring(6,10),10);
var userDate = new Date(yr,mon,dd); // Get user date in mm/dd/yyyy format
if(today.getDate() > userDate.getDate())
{
alert("Announcement date is less than Today's");
return false;
}u can change u r code based on the above code
Last edited by Tekmaven : Jul 25th, 2008 at 1:08 pm. Reason: Code tags
thnx for ur reply , i did my code like this..........
i got the output.............
i got the output.............
<html>
<head>
<title>Compare Dates</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<Script Language=Javascript>
function CompareDates()
{
var str1 = document.getElementById("fromdate").value;
var str2 = document.getElementById("todate").value;
var dt1 = parseInt(str1.substring(0,2),10);
var mon1 = parseInt(str1.substring(3,5),10);
var yr1 = parseInt(str1.substring(6,10),10);
var dt2 = parseInt(str2.substring(0,2),10);
var mon2 = parseInt(str2.substring(3,5),10);
var yr2 = parseInt(str2.substring(6,10),10);
var date1 = new Date(yr1, mon1, dt1);
alert(date1);
var date2 = new Date(yr2, mon2, dt2);
if(date2 < date1)
{
alert("To date cannot be greater than from date");
return false;
}
else
{
alert("Submitting ...");
document.form1.submit();
}
}
</Script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="">
<input type="text" name="fromdate" id="fromdate" value="20/10/2005">
<input type="text" name="todate" id="todate" value="19/10/2005">
<input type="button" value="compare dates" onclick="CompareDates()">
</form>
</body>
</html>![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- sms-chat application in vb.net(urgent help needed) (VB.NET)
- Seminar topic needed (IT Careers and Business)
- help me pls....URGENT (Java)
- Sms.. Help in vb.net (VB.NET)
- help needed in printing in java :( (Java)
- urgent help needed (Assembly)
- Mouse Problem - Help needed urgently (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: how does Scribblelive work?
- Next Thread: Lost by tried and tried


Linear Mode