This is a migrated thread and some comments may be shown as answers.

[Solved] MVC DateTimePicker set date clears selected value

0 Answers 49 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
david
Top achievements
Rank 1
david asked on 04 Feb 2011, 06:42 PM
I have a MVC - Razor DateTimePicker that i want to change the selected date on with javascript/jquery
It works fine when I change the date by a month or a year but it clears the datetimepicker when I try to change the date(by a number of days) and says the value of the datetimepicker is null if i try and read it after its been cleared.

Used in all examples:
var currentTime = new Date();
var
maxTime = datepicker.endTimeValue.value;

This works:
currentTime.setMonth(maxTime.getMonth() - 6);<br>
datepicker.value(currentTime);

This Doesn't:
currentTime.setDate(maxTime.getDate() - 7);
datepicker.value(currentTime);

Also tried:
var day = currentTime.getDate()
var month = currentTime.getMonth()
var year = currentTime.getFullYear()
var customDate = new Date();
customDate.setDate(day);
customDate.setMonth(month);
customDate.setFullYear(year);
datepicker.value(customDate);

And Also tried:
$('#DateTimePickerStart-input').val(pad(day,2) + '/' + month + 1 + '/' + year + ' 00:00');

Thank you.
Tags
General Discussions
Asked by
david
Top achievements
Rank 1
Share this question
or