Click here to Skip to main content
15,905,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Please help to select the past date up to 1 week from current date and current date from a calendar extender.
My code is as follows
HTML
<script type="text/javascript" language="javascript">
     function checkDate(sender, args) {
         var toDate = new Date();
         toDate.setMinutes(0);
         toDate.setSeconds(0);
         toDate.setHours(0);
         toDate.setMilliseconds(0);
         if (sender._selectedDate < toDate) {
             alert("You cannot select past date more than 1 week!");
             sender._selectedDate = toDate;
             // set the date back to the current date
             sender._textbox.set_Value(sender._selectedDate.format(sender._format))
         }
     }
</script>
Posted
Updated 25-Nov-14 22:05pm
v2

1 solution

C#
TimeSpan diff = senderDate- DateTime.Today;
if (diff.Days > 7) 
 {
             alert("You cannot select past date more than 1 week!");


}
 
Share this answer
 
Comments
Member 10578683 26-Nov-14 5:53am    
<script type="text/javascript" language="javascript">
function checkDate(sender, args) {
var toDate = new Date();
toDate.setMinutes(0);
toDate.setSeconds(0);
toDate.setHours(0);
toDate.setMilliseconds(0);

//var diff = sender._selectedDate - toDate;
if (sender._selectedDate - toDate > 7) {
alert("You cannot select past date more than 1 week!");
sender._selectedDate = toDate;
// set the date back to the current date
sender._textbox.set_Value(sender._selectedDate.format(sender._format))
}

}



</script>
I wrote like this but it is not working. showing the alert msg when I m selecting a future date

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