web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to Compare two DateTime Fields

(0) ShareShare
ReportReport
Posted on by 310

Hello Everyone,

I have two DateTime fields i.e. TimeIn & TimeOut and I want to compare these two fields on the basis of "Time as well as Date" using JavaScript.

Please help..

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Charles Abi Khirs Profile Picture
    3,569 on at
  • Suggested answer
    Kalpavruksh D365 CoE Profile Picture
    2,545 on at

    Hi Manoj,

    Please refer to the following link: www.digitalocean.com/.../understanding-date-and-time-in-javascript

    Please mark this answer as verified, if helped you to resolve your issue.

  • Suggested answer
    Kokulan Profile Picture
    18,054 on at

    Hi Manoj,

    On top of what Charles already suggested, you could consider using Business Rule too as they support some date time  operators that might help

    Business Rule

    8182.ScreenClip-_5B00_107_5D00_.png

    If your date time operations are a bit complex, you could also consider using a library like moment.js, please follow the links below if you are interested in knowing more about these

    https://crmtipoftheday.com/398/careful-with-those-js-libraries/

    https://gallery.technet.microsoft.com/scriptcenter/Momentjs-and-Dynamics-CRM-8bd3a264

  • Suggested answer
    Antonio Lamanna Profile Picture
    165 on at

    Hi, you can get the values from your two fields:

    var timein = Xrm.Page.getAttribute('timein').getValue();

    var timeout = Xrm.Page.getAttribute('timeout').getValue();

    create new Date for your dates:

    var inDate = new Date(timein);

    var outDate = new Date(timeout);

    compare variables:

    eg. if(inDate == outDate) { ... }

    var timein = Xrm.Page.getAttribute ('timein'). getValue ();

    var timeout = Xrm.Page.getAttribute ('timeout'). getValue ();

  • Screen one Profile Picture
    310 on at

    It Works ,Thank You !

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans