Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

while selecting current date ,showing the message as You cannot select a day earlier than today.
function checkDate(sender, args) { 
        if (sender._selectedDate) < new Date()) {               
            alert("You cannot select a day earlier than today!");
            sender._selectedDate = new Date();               
            sender._textbox.set_Value(sender._selectedDate.format(sender._format))
        }
    }

Comparison is not working properly.
please help me..
Thanks in advance

Vini
Posted
Updated 23-Sep-14 2:09am
v2
Comments
Richard MacCutchan 23-Sep-14 8:02am    
What is the value of _selectedDate, and what is returned from new Date()?
[no name] 23-Sep-14 8:10am    
have you tested with selected date should advance from today
Sinisa Hajnal 23-Sep-14 8:14am    
New Date returns date AND TIME component it is essentially DateTime.Now() from .NET

Your _selectedDate probably holds date without time (with zeroes) and the comparison is correct. Either use one of date libraries (moment.js for example) which makes this easier or set New Date into variable and then remove time component before the comparison.
Kornfeld Eliyahu Peter 23-Sep-14 8:18am    
What type sender._selectedDate has?

1 solution

Hi,

please try this
JavaScript
var selectedDate = new Date(sender._selectedDate);
if (selectedDate  < new Date()) { 

instead of this
JavaScript
if (sender._selectedDate) < new Date()) {

and update
 
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