Introduction
In our recent project, we created a PCF Control in which we designed a date-time control. In the same control, we had a requirement to format the input date value to the given Date/Time field behavior in the date/time field of Dynamics 365 CRM. In Dynamics 365 CRM, date/time field have three types of behavior such as User Local, Date Only, Time-Zone Independent as shown in the below screenshot:
To achieve this, we have used the formatTime method of formatting API in Power Apps. With this method, you can format the date/time values in dateTime field behavior.
Please find below the code to format the input date/time values in PCF Control:
//Function that return result in datetime format from input date value formatToTime (context: ComponentFramework.Context<IInputs>, inputDateValue:any) { return context.formatting.formatTime(inputDateValue, 0); } //Function that return result in datetime format from input date value formatToTime (context: ComponentFramework.Context<IInputs>, inputDateValue:any){ return context.formatting.formatTime(inputDateValue, 1); }
After running the debugger, the result of formatting input date/time values to dateTime format will be as below:
Conclusion
With the help of Formatting API in Power Apps, we can easily format the input date values to the dateTime behavior format.