{"id":1503,"date":"2021-01-07T11:21:04","date_gmt":"2021-01-07T11:21:04","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/get-current-store-date-and-time-in-magento-2\/"},"modified":"2025-07-17T10:11:58","modified_gmt":"2025-07-17T04:41:58","slug":"get-current-store-date-and-time-in-magento-2","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/get-current-store-date-and-time-in-magento-2\/","title":{"rendered":"How to Get Current Store Date and Time in Magento 2"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Developers often need to work with date and time in\u00a0Magento 2. Every store has a unique time zone. Therefore, it is essential to know how the time zone works for Magento 2 stores.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, if your store delivers the product only after a specific time of the day, you require to&nbsp;get current store date and time in Magento 2&nbsp;and prepare product delivery schedule according to the time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you save a date in Magento 2 database, it gets stored in the default time zone. But while calculating the delivery time for the above scenario, you need to convert it to the default time zone of the system to fulfil the requirement of conditional shipment like \u201cthe shipment must be done after 3 am only\u201d.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">While creating a store, you have to&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/configure-magento-2-stores-and-time-zones\/\">configure Magento 2 stores and times zones<\/a>&nbsp;and to serve the purpose of time conversion due to the time zone differences, I\u2019ve come up with the solution to&nbsp;<em>get current store date and time in Magento 2.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps to Get Current Store Date and Time in Magento 2<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">1. Create&nbsp;<strong>Data.php<\/strong>&nbsp;file<strong>&nbsp;<\/strong>and use this code.<\/p>\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 Meetanshi\\Module\\Helper;\n\nuse Magento\\Framework\\App\\Helper\\AbstractHelper;\nuse Magento\\Framework\\App\\Helper\\Context;\nuse Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface;\n\nclass Data extends AbstractHelper\n{\n    protected $timezoneInterface;\n\n    public function __construct(Context $context, TimezoneInterface $timezoneInterface)\n    {\n        $this->timezoneInterface = $timezoneInterface;\n        parent::__construct($context);\n    }\n\n    public function getStoreDateTime()\n    {\n        $formatDate = $this->timezoneInterface->formatDate();\n        \/\/ you can also get format wise date and time\n        $dateTime = $this->timezoneInterface->date()->format('Y-m-d H:i:s');\n        $date = $this->timezoneInterface->date()->format('Y-m-d');\n        $time = $this->timezoneInterface->date()->format('H:i');\n        return $dateTime;\n    }\n}<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>timezoneInterface<\/strong>&nbsp;is a considerable part of this logic and one can get date and time in various formats too!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s all.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Do consider sharing this post with Magento Community via social media.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Developers often need to work with date and time in\u00a0Magento 2. Every store has a unique time zone. Therefore, it is essential to know how&#8230;<\/p>\n","protected":false},"author":14,"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-1503","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1503","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\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=1503"}],"version-history":[{"count":4,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1503\/revisions"}],"predecessor-version":[{"id":13883,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/1503\/revisions\/13883"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=1503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=1503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=1503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}