{"id":254,"date":"2020-04-09T11:45:40","date_gmt":"2020-04-09T11:45:40","guid":{"rendered":"https:\/\/www.techcrm.in\/blogs\/?p=254"},"modified":"2020-09-08T14:53:09","modified_gmt":"2020-09-08T09:23:09","slug":"format-date-according-to-users-date-format","status":"publish","type":"post","link":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/","title":{"rendered":"Format Date according to User\u2019s Date Format"},"content":{"rendered":"\n<p>Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module.<\/p>\n\n\n\n<p>My custom function calculated date in dd\/mm\/yyyy format but the user can have any possible date formats defined by SugarCRM.<\/p>\n\n\n\n<p>Before pushing my calculated date i need to format this date according to user\u2019s settings.<\/p>\n\n\n\n<p>I did little modifications in the code and hurrah it solved my problem <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global $current_user; \/\/ Instantiate the TimeDate Class\n$timeDate = new TimeDate();\n$sampleDate = '2014-08-28'; \/\/ Sample date.\n\/\/ Call the function\n$FormatedDate = $timeDate->to_display_date($sampleDate, true, true, $current_user);\necho \"Date->\".$FormatedDate;\n\/\/If you want to get time too use the following code.\n$sampleDateTime = '2014-08-28 08:00:00'; \/\/ Sample date.\n\/\/ Call the function\n$FormatedDateTime = $timeDate->to_display_date_time($sampleDateTime, true, true, $current_user);\necho \"DateTime->\".$FormatedDateTime;<\/code><\/pre>\n\n\n<p><br>\n<br>\n<!--StartFragment--><\/p>\n\n\n<p>Hope you find this blog post helpful.<\/p>\n\n\n\n<p>Feel free to add comments and queries, that helps us to improve the quality of posts.<\/p>\n\n\n\n<p>You can contact us at&nbsp;<a rel=\"noreferrer noopener\" href=\"mailto:contact@urdhva-tech.com\" target=\"_blank\">info@techcrm.in<\/a><\/p>\n\n\n\n<p>Thank you.\n\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module. My custom function calculated date in dd\/mm\/yyyy format but the user can have any possible date formats defined by SugarCRM. Before pushing my calculated date i need to [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,9],"tags":[56,12,13],"class_list":["post-254","post","type-post","status-publish","format-standard","hentry","category-sugarcrm","category-suitecrm","tag-date-format","tag-sugarcrm","tag-suitecrm"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Format Date according to User\u2019s Date Format - TechCRM<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Format Date according to User\u2019s Date Format - TechCRM\" \/>\n<meta property=\"og:description\" content=\"Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module. My custom function calculated date in dd\/mm\/yyyy format but the user can have any possible date formats defined by SugarCRM. Before pushing my calculated date i need to [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/\" \/>\n<meta property=\"og:site_name\" content=\"TechCRM\" \/>\n<meta property=\"article:published_time\" content=\"2020-04-09T11:45:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-09-08T09:23:09+00:00\" \/>\n<meta name=\"author\" content=\"Navin Rakhonde\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Navin Rakhonde\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/\",\"name\":\"Format Date according to User\u2019s Date Format - TechCRM\",\"isPartOf\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\"},\"datePublished\":\"2020-04-09T11:45:40+00:00\",\"dateModified\":\"2020-09-08T09:23:09+00:00\",\"author\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SugarCRM\",\"item\":\"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Format Date according to User\u2019s Date Format\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#website\",\"url\":\"https:\/\/www.techcrm.in\/blogs\/\",\"name\":\"TechCRM\",\"description\":\"Blog\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc\",\"name\":\"Navin Rakhonde\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g\",\"caption\":\"Navin Rakhonde\"},\"sameAs\":[\"https:\/\/www.techcrm.in\/\"],\"url\":\"https:\/\/www.techcrm.in\/blogs\/author\/navin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Format Date according to User\u2019s Date Format - TechCRM","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/","og_locale":"en_US","og_type":"article","og_title":"Format Date according to User\u2019s Date Format - TechCRM","og_description":"Quite recently, I faced an issue wherein I have to push some calculated date(based on some algo) to the date field on EditView of a custom module. My custom function calculated date in dd\/mm\/yyyy format but the user can have any possible date formats defined by SugarCRM. Before pushing my calculated date i need to [&hellip;]","og_url":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/","og_site_name":"TechCRM","article_published_time":"2020-04-09T11:45:40+00:00","article_modified_time":"2020-09-08T09:23:09+00:00","author":"Navin Rakhonde","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Navin Rakhonde","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/","url":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/","name":"Format Date according to User\u2019s Date Format - TechCRM","isPartOf":{"@id":"https:\/\/www.techcrm.in\/blogs\/#website"},"datePublished":"2020-04-09T11:45:40+00:00","dateModified":"2020-09-08T09:23:09+00:00","author":{"@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc"},"breadcrumb":{"@id":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.techcrm.in\/blogs\/format-date-according-to-users-date-format\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.techcrm.in\/blogs\/"},{"@type":"ListItem","position":2,"name":"SugarCRM","item":"https:\/\/www.techcrm.in\/blogs\/category\/sugarcrm\/"},{"@type":"ListItem","position":3,"name":"Format Date according to User\u2019s Date Format"}]},{"@type":"WebSite","@id":"https:\/\/www.techcrm.in\/blogs\/#website","url":"https:\/\/www.techcrm.in\/blogs\/","name":"TechCRM","description":"Blog","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.techcrm.in\/blogs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/992dfe427bb53dcdfd72dd80e3ef9dbc","name":"Navin Rakhonde","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.techcrm.in\/blogs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9cc8fd1b948255055b85e5d41dabfc6e704f806d180a1e21cb8fb378e2f5c022?s=96&d=mm&r=g","caption":"Navin Rakhonde"},"sameAs":["https:\/\/www.techcrm.in\/"],"url":"https:\/\/www.techcrm.in\/blogs\/author\/navin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/comments?post=254"}],"version-history":[{"count":1,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/254\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/posts\/254\/revisions\/256"}],"wp:attachment":[{"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/media?parent=254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/categories?post=254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcrm.in\/blogs\/wp-json\/wp\/v2\/tags?post=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}