Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 general forum

Extract Time Info from DateTime Field

Posted on by 375

Hello D365 Community, 

I cannot seem to find a "simple" way of extracting the TIME only from a DATETIME field in D365.  Our specific scenario is that we need to provide the Start and End time values in an email template but the source is an OOB DATETIME field, which of course we need the Date for other requirements.  Is there a tool or method in which to achieve this?  I am open to any alternate recommendations as well.

  • Suggested answer
    LeoAlt Profile Picture
    LeoAlt 16,329 on at
    RE: Extract Time Info from DateTime Field

    Hi partner,

    There are 2 ways for you.

    1.Use js code to transfer the datetime from “yyyy-mm-dd hh:mm:ss” to "yyyy-mm-dd", You could add js code on the onload event of email.

    Here are the sample code.

    var startDate = Xrm.Page.getAttribute("yourattributename").getValue();

    var hours = startDate.getHours();

    var minutes = startDate.getMinutes();

    alert(hours + ":" + minutes);

    2.You could change the email template xml.

    https://community.dynamics.com/crm/b/mscrmcustomization/posts/email-template-show-date-or-time-portion-only-for-datetime-attribute

    Hope it helps.

    Best Regards,

    Leo

  • Suggested answer
    Adrian Begovich Profile Picture
    Adrian Begovich 21,009 Super User 2024 Season 2 on at
    RE: Extract Time Info from DateTime Field

    Hi RugerSR762,

    You can obtain the time with JavaScript.

    Example JavaScript code:

    function getTime()

    {

    var startDate = Xrm.Page.getAttribute("startdate").getValue();

    var endDate = Xrm.Page.getAttribute("enddate").getValue();

    var startHours = startDate.getHours();

    var startMinutes = startDate.getMinutes();

    var endHours = endDate.getHours();

    var endMinutes = endDate.getMinutes();

    }

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