How to add hours to a date field in CRM (onSave)

Hi!

I have used code from the Experts Exchange website to add ONE week day to a date field in CRM.

        var TODAY;
        TODAY = crmForm.all.new_targetstart.DataValue
         var addDays = [1,1,1,1,1,3,2];
         TODAY.setDate( TODAY.getDate() + addDays[TODAY.getDay()]);

         crmForm.all.new_targetfinish.DataValue =TODAY;

I also need to add hours to TODAY.
How do I do that?
juttaReimannAsked:
Who is Participating?
 
Feridun KadirConnect With a Mentor Principal ConsultantCommented:
How about something like the code below to add hours.




// Assume the date is on the form in a field called new_date
// and the hours to add are in a field called new_hours
 
adate= crmForm.all.new_adate.DataValue;
addhours=crmForm.all.new_hours.DataValue;

// Get the hour in the date and add the required hours to it

hour=adate.getHours();
hour = hour + addhours;

//Update the date with the new hour and update the field on the form. 
//If more than 23 hours are added, the date gets incremented

adate.setHours(hour);
crmForm.all.new_adate.DataValue=adate;

Open in new window

0
 
juttaReimannAuthor Commented:
Thanks for a brilliant solution.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.