I have a datepicker in 2 textboxes , in am trying to add the value of these text boxes to a function that needs a valid Javascript Date.
This is the part of the function - start is a Date
else if (daystosearch == 'custom') {
start.setDate(Date.parse($('#<%= tStartDate.ClientID %>').val()));
end.setDate(Date.parse($('#<%= tEndDate.ClientID %>').val()));
}
Date.Parse will not work , because value of the textbox is "10/29/2012" which is not a parsable date. How can I use start.setDate and get the value of the textboxes date ?
If the value of the textbox is something like "10/29/2012", you should be able to use:
var new_start = new Date($('#<%= tStartDate.ClientID %>').val());
But if you're trying to use setDate, the value that it accepts is an integer from 1-31, so you need to use getDate on the new Date object, like:
var new_start = new Date($('#<%= tStartDate.ClientID %>').val());
start.setDate(new_start.getDate());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With