Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Calculate Date Time Difference in Business Hours

Posted on by 222

Hi All,

I have requirement to calculate the time difference (in business hours/minute) between two date time fields in Dynamics 365. I have different business units in my organisation and which is under different time zone. Is there any way that I can get the time difference in business hours ?

Thank you in advance.

Regards,

Abhiram

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Calculate Date Time Difference in Business Hours

    hi try this

    function DOBvalid() {

       var oneDay = 24 * 60 * 60 * 1000;

       var DOB = Xrm.Page.getAttribute("new_dob").getValue();

       var Today = new Date();

       var diffDays = Math.abs((DOB.getTime() - Today.getTime()) / (oneDay));

       alert(diffDays);

       /*var age = DOB

       if (DOB > Today) {

           alert('Date of birth can not be greater than the date today');

           Xrm.Page.getAttribute("new_dob").setValue(null); //set null value

       */

    }

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,074 on at
    RE: Calculate Date Time Difference in Business Hours

    Hi Abhiram,

    You could try using a calculated field to calculate the difference between the two date time fields.

    See: mydynamicscrmblog.wordpress.com/.../calculating-difference-between-two-time-fields-in-crm-2015-without-javascripts/

    Or you could create a simple field with floating point number data type and populate the field using javascript.

    See the links below.

    community.dynamics.com/.../239306

    social.microsoft.com/.../calculate-time-difference-between-two-datetime-fields-hoursminsec-in-jscript-ms-crm-2011

    crm.ipiyush.me/calculate-duration-fields-in-dynamics-crm-2011-via-code-javascript-and-c

    Hope this helps.

  • Abhiram Thulasi Profile Picture
    Abhiram Thulasi 222 on at
    RE: Calculate Date Time Difference in Business Hours

    Hi,

    Thanks for your reply. I have tried to create one plugin for achieving the same by referring the below blog. However if the two dates are in the same day it is returning 0. If you have any  blog/site reference  please share.

    crmmemories.blogspot.ae/.../calculate-working-time-between-two.html

    Regards,

    Abhiram

  • ashlega Profile Picture
    ashlega 34,475 on at
    RE: Calculate Date Time Difference in Business Hours

    Hi,

     I'm not sure how the calculations would work (and where would you define the business hours per business unit etc).. sounds like you may need a plugin for this kind of calculations.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans