How to get a date to fall on the next sunday everytime RRS feed

  • Question

  • Hi, <o:p></o:p>

    I was
    wondering if I could get some advice on how to get a date to always fall on a
    Sunday. I am utilising the code below which works to the extent that it is
    adding the 2 years as needed however I need it to always fall on the Sunday
    after. A user should always enter a Mondays date into the
    kf_tenancyconversiondate this then looks at the tenancy type and if this says 2
    years then should add 2 years to the kf_tenancyconversiondate date and enter
    the next Sundays date. Any advice on how this works will really be helpful.<o:p></o:p>

    Thank you
    in advance<o:p></o:p>



    var CRM_FORM_TYPE_CREATE = "1";
    var DUE;
    var i = 0;
    var days_to_add = 730;
    var ttype = crmForm.all.kf_tenancytype.DataValue;
    if (ttype == 1)
         DUE = new Date(crmForm.all.kf_tenancyconversiondate.DataValue.getTime() + (days_to_add*24*60*60*1000));
         //0 = Sunday, 6 = Saturday, if the date not equals a weekend day then increase by 1
         if (DUE.getDay() != 0 && DUE.getDay() != 6)
          days_to_add += 1;
    DUE = new Date(crmForm.all.kf_tenancyconversiondate.DataValue.getTime() + (days_to_add));
    crmForm.all.kf_enddatefixedtermtenancy.DataValue = DUE;

    Thursday, September 3, 2015 11:56 AM