Quantcast
Channel: Sam's Activities
Viewing all articles
Browse latest Browse all 3363

Format date-time value using Formatting API in PCF Control

$
0
0

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:

PCF Control

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:

PCF Control

Conclusion

With the help of Formatting API in Power Apps, we can easily format the input date values to the dateTime behavior format.

Attach2Dynamics

 


Viewing all articles
Browse latest Browse all 3363

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>