{"id":679,"date":"2019-11-17T22:28:25","date_gmt":"2019-11-17T22:28:25","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/2019\/11\/17\/set-date-format-in-magento-2\/"},"modified":"2025-07-23T09:47:36","modified_gmt":"2025-07-23T04:17:36","slug":"set-date-format-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/set-date-format-in-magento-2\/","title":{"rendered":"How To Set Date Format In Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">There&#8217;s no surprise that Magento 2 is a global platform serving online businesses of all types. Magento 2 stores host visitors from all around the globe.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Every country does not follow the same date and time format. So, as per your Magento 2 store target audience, you need to configure the date and time options for the sake of customer convenience.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If you keep on using the default setting and the customers are using some different formats, it may confuse them.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Confusion is undoubtedly going to result in the visitors abandoning your store! We don&#8217;t want that.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">So, it is ultra necessary to configure options like date &amp; time, currencies, etc. as per the target customer base&#8217;s locale.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">As a part of it, I&#8217;ve come up with two methods to <strong>set date format in Magento 2<\/strong>,<i><\/i> as stated below:<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Methods to Set Date Format in Magento 2:<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">From the Admin Panel:<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">1. <strong>Login<\/strong> to admin panel<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. Go to <strong>Stores &gt; Configuration<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Under <strong>Catalog<\/strong>, select <strong>Catalog<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">4. Expand <strong>Date &amp; Time Custom Options<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Use JavaScript Calendar<\/strong> \u2013 Set to \u201cYes\u201d if you want to use the popup calendar for date fields.<\/li>\n\n\n\n<li><strong>Date Fields Order<\/strong> \u2013 Set this field according to the format you require. For example, MM\/DD\/YY or DD\/MM\/YY<\/li>\n\n\n\n<li><strong>Time Format<\/strong> \u2013 Choose the 12-hour format or the 24-hour format from the dropdown<\/li>\n\n\n\n<li><strong>Year Range<\/strong> \u2013 Enter the year to set the from and to dates for the year range in the dropdown. If this field is left blank, it takes the default value as the current year.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">5. <strong>Save<\/strong> configuration<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2019\/11\/How-to-set-date-format-in-Magento-2-1.gif\" alt=\"Methods to Set Date Format in Magento 2\" class=\"wp-image-52637\" style=\"object-fit:cover\"\/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Programmatically:<\/h3>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\nnamespace Vendor\\Extension\\Model;\nuse Magento\\Framework\\Stdlib\\DateTime\\DateTimeFactory;\nclass ChangeDate\n{\n    private $dateTimeFactory;\n    public function __construct(\n        DateTimeFactory $dateTimeFactory\n    ) {\n        $this->dateTimeFactory = $dateTimeFactory;\n    }\n    public function getDateByFormat($format)\n    {\n        $dateModel = $this->dateTimeFactory->create();\n        return $dateModel->gmtDate($format);\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Set custom date and time format in Magento 2 store using any of the above methods and offer excellent user experience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There&#8217;s no surprise that Magento 2 is a global platform serving online businesses of all types. Magento 2 stores host visitors from all around the&#8230;<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-679","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/679","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=679"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions"}],"predecessor-version":[{"id":19100,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/679\/revisions\/19100"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=679"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=679"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=679"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}