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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

question about data type

(0) ShareShare
ReportReport
Posted on by 2,665

Hi,

I am wondering if there is any way I can use only time part from the date and time data type field?

Or is there a way to hide or lock or disable the date part while date remains current date by default and only enable time part?

If anybody has done any modifications to date and time field like above, would you please share your suggestions or ideas?

Thanks for any help!

*This post is locked for comments

I have the same question (0)
  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: question about data type

    Thanks Wei.

  • Verified answer
    crmprogrammer2013 Profile Picture
    2,665 on at
    RE: question about data type

    Thanks Goutam, I think the second option works for me too. Meanwhile, I found an article where a dropdown is used to select time using a html webresource. This works well but once you refresh the page, the value in the dropdown goes back to 12AM.

    Not sure if we can retain the last selected value by the user. The selected value is set to the datetime field(hidden) without any problem and seems to be working as expected. The only problem is not retaining the selected value of the dropdown after refresh. Do you have any suggestions for me in regards to this?

    Here is the link to the article:

    mahadeomatre.blogspot.com/.../show-only-time-for-date-time-attribute.html

    Thanks again.

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: question about data type

    Hi,

    Sample code for V9.0

    Register the below JS on date field change.

    function setfield(formContext) {

       var datefield = formContext.getControl('arg').getValue(); //replace the arg into the date field schema name

       var time = datefield.getHours() + ":" + datefield.getMinutes();

       formContext.getAttribute('arg').setValue(time) // replace the arg into the string field schema name

    }

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: question about data type

    Hello Roxanna,

    If you hide the date time field user can not select the time , so you need to  show the date time field to allow to fill the date and time part. Once selected the date time in the onchange you get the time part using JavaScript and set it to text field , so text field will be always read only.

    I think my second options is better manually fill the time part and validate using JS with proper message instead of creating two field.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: question about data type

    Hi,

    Goutam means that, you can create a date field and a string field, write a JS to trigger on date field change, and set the time into the string field.

  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: question about data type

    Thanks Goutam. That sounds interesting.

    I'd like to try but I didn't quite follow this line..

    OnLoad or field OnChange event get the time part from date time field and set value to your text field.

    You mean, first create a date time field and hide it and then get the time part from it?

    I want my users to be able to select the time from the dropdown values. How is it possible with your approach. Could you please elaborate?

    Thanks again!

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at
    RE: question about data type

    Hello Roxanna,

    Unfortunately this is not possible for date time field.

    However as an alternate way you can create a text field and in the form  OnLoad or field OnChange event get the time part from date time field and set value to your text field.

    You can also  create text field and  using javascript validate particular format onkeypress event  like 3:15:00 AM , if format does  not match then you can show alert.

    Hope this helps.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: question about data type
    Hi,

    Here you go.

    sample java script to get time

    var d = new Date(); // for now, you can change it to get the field value. d.getHours(); // => 9 d.getMinutes(); // => 30 d.getSeconds(); // => 51

    Check below articles if you plan to go for html

    https://msdn.microsoft.com/en-us/library/gg309473.aspx

    https://crmbook.powerobjects.com/extending-crm/javascript/html-web-resources/

    https://arunpotti.wordpress.com/tag/html-webresource-example-in-crm-2015/

    https://nishantrana.me/2011/10/31/using-html-web-resource-in-crm-2011/

    If you plan for custom field
    var d = new Date(); // for now, you can change it to get the field value.
    d.getHours(); // => 9
    d.getMinutes(); // =>  30
    d.getSeconds(); // => 51

    getValue
    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/controls/getvalue

    s
    etValue

    https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/clientapi/reference/attributes/setvalue


     
  • crmprogrammer2013 Profile Picture
    2,665 on at
    RE: question about data type

    Hi, is there an example that I can refer to?

    Thanks.

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: question about data type

    Hi,

    this is not possible in out of the box feature, go for html page or custom text field instead.

    technet.microsoft.com/.../dn946904.aspx

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#3
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans