locked
How to add 16 years to the entered date? RRS feed

  • Question

  • Hi All,

    I am having a date field in which I need to add +16 years for the value entered , please share me the code how to do this in ms crm 2013

    and also need to keep default to todays date for another field.

    Wednesday, May 14, 2014 10:05 AM

Answers

  • Hi All,

    I am having a date field in which I need to add +16 years for the value entered , please share me the code how to do this in ms crm 2013

    and also need to keep default to todays date for another field.

    to add 16 years you can use this function:

    function Add16Years() {
    var dateValue = Xrm.Page.getAttribute("new_datefield").getValue();
    if (dateValue != null) {
       dateValue.setFullYear(dateValue.getFullYear()+16);
       Xrm.Page.getAttribute("new_datefield2").setValue(dateValue);
    }
    }
    for today date you can use the function provided by Ketan


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Wednesday, May 14, 2014 11:15 AM
  • todays date it is working fine but it should not accept future dates.. How can I do this

    Thank you very much

     

    if you don't want to accept future dates inside a field, you need to put this code inside the onchange event:

    function dateOnChange() {
    var selectedDate = Xrm.Page.getAttribute("new_datefield").getValue();
    selectedDate.setHours(0,0,0,0);
    var today = new Date();
    today.setHours(0,0,0,0);
    if (selectedDate.getTime() > today.getTime())
    {
      Xrm.Page.getAttribute("new_datefield").setValue(null);
      alert("It is not possible to choose a future date");
    }
    }



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, May 14, 2014 11:55 AM

All replies

  • function ChangeUpdate()
    {

    var dt = new Date();
    dt.setFullYear(2020);
    dt.setMonth(0);
    dt.setDate(01);
    Xrm.Page.getAttribute("new_dncexpirationdate").setValue(dt);//above code will set the value by user defined

    }

    function ForToday_Date()

    {

    var dt = new Date();

    Xrm.Page.getAttribute("new_dncexpirationdate").setValue(dt);// it will give current date to given field

    }

    Wednesday, May 14, 2014 10:12 AM
  • hi,

    I already had a dob field in which date of birth is entered now there is another field in which I need to add +16 years to the date of birth and set the value there.

    And also one date field is there in which I need to restrict future dates. Please send me the code which helps me a lot.... 

    Thank You

    Wednesday, May 14, 2014 11:12 AM
  • Hi All,

    I am having a date field in which I need to add +16 years for the value entered , please share me the code how to do this in ms crm 2013

    and also need to keep default to todays date for another field.

    to add 16 years you can use this function:

    function Add16Years() {
    var dateValue = Xrm.Page.getAttribute("new_datefield").getValue();
    if (dateValue != null) {
       dateValue.setFullYear(dateValue.getFullYear()+16);
       Xrm.Page.getAttribute("new_datefield2").setValue(dateValue);
    }
    }
    for today date you can use the function provided by Ketan


    My blog: www.crmanswers.net - Rockstar 365 Profile


    Wednesday, May 14, 2014 11:15 AM
  • todays date it is working fine but it should not accept future dates.. How can I do this

    Thank you very much

     

    Wednesday, May 14, 2014 11:28 AM
  • todays date it is working fine but it should not accept future dates.. How can I do this

    Thank you very much

     

    if you don't want to accept future dates inside a field, you need to put this code inside the onchange event:

    function dateOnChange() {
    var selectedDate = Xrm.Page.getAttribute("new_datefield").getValue();
    selectedDate.setHours(0,0,0,0);
    var today = new Date();
    today.setHours(0,0,0,0);
    if (selectedDate.getTime() > today.getTime())
    {
      Xrm.Page.getAttribute("new_datefield").setValue(null);
      alert("It is not possible to choose a future date");
    }
    }



    My blog: www.crmanswers.net - Rockstar 365 Profile

    Wednesday, May 14, 2014 11:55 AM