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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Feridun KadirPrincipal 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
juttaReimannAuthor Commented:
Thanks for a brilliant solution.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Dynamics

From novice to tech pro — start learning today.