{"id":31823,"date":"2022-06-15T14:09:50","date_gmt":"2022-06-15T08:39:50","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=31823"},"modified":"2022-06-15T11:43:15","modified_gmt":"2022-06-15T06:13:15","slug":"format-date-time-value-using-formatting-api-in-pcf-control","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2022\/06\/format-date-time-value-using-formatting-api-in-pcf-control\/","title":{"rendered":"Format date-time value using Formatting API in PCF Control"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>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 <a href=\"https:\/\/docs.microsoft.com\/en-us\/power-apps\/developer\/component-framework\/reference\/datetimefieldbehavior\" target=\"_blank\" rel=\"noopener\">Date\/Time field behavior<\/a> 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:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-31824\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/1PCF-Control.jpeg\" alt=\"PCF Control\" width=\"832\" height=\"514\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/1PCF-Control.jpeg 832w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/1PCF-Control-300x185.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/1PCF-Control-768x474.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/1PCF-Control-660x408.jpeg 660w\" sizes=\"(max-width: 832px) 100vw, 832px\" \/><\/p>\n<p>To achieve this, we have used the <strong>formatTime<\/strong> method of formatting API in Power Apps. With this method, you can format the date\/time values in dateTime field behavior.<\/p>\n<p>Please find below the code to format the input date\/time values in PCF Control:<\/p>\n<pre class=\"lang:css gutter:true start:1\">\/\/Function\u00a0that\u00a0return\u00a0result\u00a0in\u00a0datetime\u00a0format\u00a0from\u00a0input\u00a0date value\r\n\r\nformatToTime\r\n\r\n(context:\u00a0ComponentFramework.Context&lt;IInputs&gt;,\u00a0inputDateValue:any)\u00a0{\r\n\r\nreturn\u00a0context.formatting.formatTime(inputDateValue, 0);\r\n\r\n}\r\n\r\n\/\/Function\u00a0that\u00a0return\u00a0result\u00a0in\u00a0datetime\u00a0format\u00a0from\u00a0input\u00a0date value\r\n\r\nformatToTime (context:\u00a0ComponentFramework.Context&lt;IInputs&gt;,\u00a0inputDateValue:any){\r\n\r\nreturn\u00a0context.formatting.formatTime(inputDateValue, 1);\r\n\r\n}<\/pre>\n<p>After running the debugger, the result of formatting input date\/time values to dateTime format will be as below:<\/p>\n<p><img decoding=\"async\" class=\"alignnone wp-image-31825\" style=\"border: 1px solid #0a0a0a; padding: 1px; margin: 1px;\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/2PCF-Control.jpeg\" alt=\"PCF Control\" width=\"973\" height=\"385\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/2PCF-Control.jpeg 556w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/2PCF-Control-300x119.jpeg 300w\" sizes=\"(max-width: 973px) 100vw, 973px\" \/><\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>With the help of Formatting API in Power Apps, we can easily format the input date values to the dateTime behavior format.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/attach-2-dynamics-365-crm-upload-multiple-files-sharepoint-cloud-storage\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone wp-image-31827\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/A2D.jpg\" alt=\"Attach2Dynamics\" width=\"840\" height=\"210\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/A2D.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/A2D-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/A2D-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2022\/06\/A2D-660x165.jpg 660w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2022\/06\/format-date-time-value-using-formatting-api-in-pcf-control\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,1929],"tags":[1941],"class_list":["post-31823","post","type-post","status-publish","format-standard","hentry","category-dynamics-365","category-pcf","tag-pcf-control"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=31823"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/31823\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=31823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=31823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=31823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}