Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert DatePicker textbox into javascript Date

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 ?

like image 218
Scott Selby Avatar asked Jul 14 '26 06:07

Scott Selby


1 Answers

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());
like image 153
Ian Avatar answered Jul 17 '26 18:07

Ian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!