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

[Solved] get the value from DatePicker

4 Answers 106 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
nav100
Top achievements
Rank 1
nav100 asked on 30 Dec 2010, 09:06 PM
I am trying to get the value from the DatePicker. But I am getting 'undefined' message. What could be the issue? Here is my code. Also I am trying to get the date difference from 2 DatePickers.

<%

 

= Html.Telerik().DatePicker()

 

 

.Name(

 

"EndDate")

 

 .ClientEvents(events => events.OnClose(

 

"DatePicker_onChange")) %>

function
DatePicker_onChange() {

 

 

 

// var datepicker = $(this).data('tEndDate');

 

 

var date2 = $('#EndDate').data("tEndDate");

 

 

 alert(date2);

 

 

 }

4 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 03 Jan 2011, 09:59 AM
Hi Nara,

You're unable to access the date picker because of the wrong data key. It should be:
$(this).data('tDatePicker')

The value can be obtained by calling the value() method of the date picker object.

Please refer to this help topic for detailed explanation and examples - DatePicker - Client API and Events

Date calculations in JavaScript require some attention and can lead to incorrect results if you don't take Daylight Saving Time into account. The following function calculates the difference between two dates (in ticks):

function subtractDate(date, dateToSubtract)
{
    var timePerMinute = 60000;
    var diff = date.getTime() - dateToSubtract;
     
    // Compensate for the missing/extra hour during DST change
    var tzOffsetDiff = date.getTimezoneOffset() - dateToSubtract.getTimezoneOffset();
 
    return diff - (tzOffsetDiff * timePerMinute);
};

Please refer to this and similar sites if you need additional information for working with the JavaScript Date object - JavaScript Date Object

I hope this helps.

Best regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
nav100
Top achievements
Rank 1
answered on 04 Jan 2011, 04:02 PM
I have tried using

$(this).data('tDatePicker') but still I couldn't get it working. It doesn't throw any exception. What could possibly wrong?

0
Accepted
T. Tsonev
Telerik team
answered on 04 Jan 2011, 04:48 PM
Hi Nara,

I've attached a sample project that demonstrates how to access the DatePicker value.

Best regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
nav100
Top achievements
Rank 1
answered on 04 Jan 2011, 08:14 PM
Thanks. It worked.
Tags
Date/Time Pickers
Asked by
nav100
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
nav100
Top achievements
Rank 1
Share this question
or