{"id":28244,"date":"2021-06-15T11:19:13","date_gmt":"2021-06-15T11:19:13","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=28244"},"modified":"2021-09-01T09:36:28","modified_gmt":"2021-09-01T09:36:28","slug":"how-to-read-and-set-date-format-of-logged-in-user-in-pcf-control","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/06\/how-to-read-and-set-date-format-of-logged-in-user-in-pcf-control\/","title":{"rendered":"How to Read and Set Date Format of Logged-in User in PCF Control"},"content":{"rendered":"<h2 style=\"text-align: justify;\"><strong>Introduction<\/strong><\/h2>\n<p style=\"text-align: justify;\">Recently in our PCF control, we got the requirement that when the user selects a date from the calendar control then that date format should be of logged-in user. In this blog, we will check how to achieve the same.<\/p>\n<h3 style=\"text-align: justify;\">Scenario:<\/h3>\n<p style=\"text-align: justify;\">Here is my current user settings in Dynamics 365 CRM.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog.jpeg\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-28245\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"970\" height=\"690\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog.jpeg 970w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog-300x213.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog-768x546.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/1-ReadAndSetDateFormatBlog-660x469.jpeg 660w\" sizes=\"(max-width: 970px) 100vw, 970px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">As you can see here, the date format are as follows:<\/p>\n<p style=\"text-align: justify;\">Short date: yyyy\/MM\/dd<\/p>\n<p style=\"text-align: justify;\">Long date: MMMM,d,yyyy<\/p>\n<p style=\"text-align: justify;\">In this example, I will be retrieving short date format.<\/p>\n<h3 style=\"text-align: justify;\">Example<\/h3>\n<p style=\"text-align: justify;\">Here is the pop-up window in which I want to retrieve some basic user information including their joining date.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/2-ReadAndSetDateFormatBlog.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28246 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/2-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"276\" height=\"262\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">For Joining date field, I have used fabric UI datepicker control. Now when the user selects a date from datepicker like below then I want to set the date in the format of current logged-in user.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/3-ReadAndSetDateFormatBlog.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28247 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/3-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"335\" height=\"315\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/3-ReadAndSetDateFormatBlog.jpeg 335w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/3-ReadAndSetDateFormatBlog-300x282.jpeg 300w\" sizes=\"(max-width: 335px) 100vw, 335px\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\"><strong>Get the Date Format<\/strong><\/h3>\n<p style=\"text-align: justify;\">To get the logged-in user date format settings, I have retrieved dateFormattingInfo from PCF context object as below:<\/p>\n<p style=\"text-align: justify;\">Context.userSettings.dateFormattingInfo.shortDatePattern. \/\/For Short Date Format.<\/p>\n<p style=\"text-align: justify;\">Context.userSettings.dateFormattingInfo.longDatePattern. \/\/For Long Date Format.<\/p>\n<h3 style=\"text-align: justify;\"><strong>Set the date in datepicker control<\/strong><\/h3>\n<p style=\"text-align: justify;\">To set the retrieved date format to the datepicker control, I have used formatDate property of datepicker control.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28248 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"884\" height=\"170\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog.jpeg 884w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog-300x58.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog-768x148.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/4-ReadAndSetDateFormatBlog-660x127.jpeg 660w\" sizes=\"(max-width: 884px) 100vw, 884px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Here is the function to set the user selected date:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28249 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"1051\" height=\"389\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog.jpeg 1051w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog-300x111.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog-768x284.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog-1024x379.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/5-ReadAndSetDateFormatBlog-660x244.jpeg 660w\" sizes=\"(max-width: 1051px) 100vw, 1051px\" \/><\/a><\/p>\n<h3 style=\"text-align: justify;\"><strong>Result<\/strong><\/h3>\n<p style=\"text-align: justify;\">As you can see in the below image, I was able to set the date in logged-in user&#8217;s format(yyyy\/MM\/dd )<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/6-ReadAndSetDateFormatBlog.jpeg\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28250 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/6-ReadAndSetDateFormatBlog.jpeg\" alt=\"ReadAndSetDateFormat\" width=\"220\" height=\"220\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/6-ReadAndSetDateFormatBlog.jpeg 220w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/06\/6-ReadAndSetDateFormatBlog-150x150.jpeg 150w\" sizes=\"(max-width: 220px) 100vw, 220px\" \/><\/a><\/p>\n<h2 style=\"text-align: justify;\"><strong>Conclusion<\/strong><\/h2>\n<p style=\"text-align: justify;\">With the help of <strong>Context.userSettings.dateFormattingInfo.shortDatePattern<\/strong>, we can read and set date from logged-in user&#8217;s date format.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/kanban-board-dynamics-365-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"wp-image-28102 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/05\/KB_2.jpg\" alt=\"\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/05\/KB_2.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/05\/KB_2-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/05\/KB_2-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/05\/KB_2-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction Recently in our PCF control, we got the requirement that when the user selects a date from the calendar control then that date format should be of logged-in user. In this blog, we will check how to achieve the same. Scenario: Here is my current user settings in Dynamics 365 CRM. As you can\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/06\/how-to-read-and-set-date-format-of-logged-in-user-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":[11,1929],"tags":[1941,2291,2302,2303],"class_list":["post-28244","post","type-post","status-publish","format-standard","hentry","category-controls","category-pcf","tag-pcf-control","tag-pcf-dataset-control","tag-read-date","tag-set-date"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/28244","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=28244"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/28244\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=28244"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=28244"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=28244"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}