Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

How to identify Time is selected in Date Time control javascript mscrm

Posted on by 475

Hello,

I want to compare 2 datetime fields. On change of Date field itself javascript is triggering but i want to check with time field as well while comparing to datetime fields.

Is possible to identify whether time is selected in datetime control thru javascript? by default time is value is getting as "12:00:00 AM" for  Date.toLocaleTimeString().

Please help

  • Suggested answer
    Vipin J Profile Picture
    Vipin J 1,583 on at
    RE: How to identify Time is selected in Date Time control javascript mscrm

    Hi Krishna,

    In Dynamic CRM a datetime field always contains both values Date & Time, therefore it is auto setting its value to 12:00:00 AM.

    Even if you change the setting to Date Only in field properties, it will still have Date & Time stored in Database.

    In Javascript or C# you will get a complete Date and Time Value.

    Just use below simple logic to compare two date fields.

    .dateIsEqual = function (date1, date2) {
    if (date1 === date2)
    return true;
    return false;
    };

    Here are some more best practise for coding JavaScript for Dynamic CRM.

    https://vjcity.blogspot.com/2019/08/guidelines-to-write-good-javascript.html

  • cloflyMao Profile Picture
    cloflyMao 25,198 on at
    RE: How to identify Time is selected in Date Time control javascript mscrm

    Hi Krishna,

    Do you mean you want to trigger your own javascript in onChange field?

    For example, when you select a date from date2 field, and then trigger a script in this onChange event?

    Once you get a date value from date time field in CRM, you can call any methods for it as Date Object in native Javascript. (getMinutes(), getSeconds() etc.)

    I would get better understanding for your requirement if you could share me your business logic in details. Thanks.

    Regards,

    Clofly 

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans