GetYears problem

3 posts, 0 answers
  1. Yoni Dagan
    Yoni Dagan avatar
    45 posts
    Member since:
    Sep 2009

    Posted 18 Jun 2008 Link to this post

    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. Maria Ilieva
    Admin
    Maria Ilieva avatar
    4017 posts

    Posted 23 Jun 2008 Link to this post

    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
  3. Yoni Dagan
    Yoni Dagan avatar
    45 posts
    Member since:
    Sep 2009

    Posted 23 Jun 2008 Link to this post

    Thank you,problem fixed.
Back to Top