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

GetYears problem

2 Answers 70 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
Yoni Dagan
Top achievements
Rank 1
Yoni Dagan asked on 18 Jun 2008, 01:44 PM

function

OnBirthDateSelected(sender, e)

{

var datePicker;

//if (pickerID == null)

{

datePicker = $find(

"radDatePicker");

var now=new Date();

var yearnow=now.getYear();

var monthnow = now.getMonth()+1;

var daynow = now.getDay();

var date = datePicker.GetDate();

var years = yearnow - date.getYear();

if(years < 0)

{

document.getElementById(

"tb_age").value = "NaN";

return;

}

if (monthnow < date.getMonth() && (date.getMonth() - monthnow) >= 6 )

years--;

document.getElementById(

"tb_age").value = years.toString();

}

}

The function that calculate age but date.getYear(); return me not 1940 only 40
How i can decide the problem.

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 23 Jun 2008, 11:48 AM
Hello Sergey,

The getYear() method returns the year, as a two-digit OR a four-digit number. For years between 1900 and 1999 the getYear() method returns only two digits. For years before 1900 and after 1999 it returns four digits.
For getting the correct four digits for particular year please use the getFullYear() method instead. For more information on this matter, you could refer to the following topic.

Sincerely yours,
Maria Ilieva
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Yoni Dagan
Top achievements
Rank 1
answered on 23 Jun 2008, 12:07 PM
Thank you,problem fixed.
Tags
Calendar
Asked by
Yoni Dagan
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Yoni Dagan
Top achievements
Rank 1
Share this question
or