🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How To Set Date Format In Magento 2

By Sanjay JethvaUpdated on Mar 18, 2025 3 min read

There’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.

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.

If you keep on using the default setting and the customers are using some different formats, it may confuse them.

Confusion is undoubtedly going to result in the visitors abandoning your store! We don’t want that.

So, it is ultra necessary to configure options like date & time, currencies, etc. as per the target customer base’s locale.

As a part of it, I’ve come up with two methods to set date format in Magento 2, as stated below:

Methods to Set Date Format in Magento 2:

From the Admin Panel:

1. Login to admin panel

2. Go to Stores > Configuration

3. Under Catalog, select Catalog

4. Expand Date & Time Custom Options

  • Use JavaScript Calendar – Set to “Yes” if you want to use the popup calendar for date fields.
  • Date Fields Order – Set this field according to the format you require. For example, MM/DD/YY or DD/MM/YY
  • Time Format – Choose the 12-hour format or the 24-hour format from the dropdown
  • Year Range – 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.

5. Save configuration

Programmatically:

<?php
namespace Vendor\Extension\Model;
use Magento\Framework\Stdlib\DateTime\DateTimeFactory;
class ChangeDate
{
    private $dateTimeFactory;
    public function __construct(
        DateTimeFactory $dateTimeFactory
    ) {
        $this->dateTimeFactory = $dateTimeFactory;
    }
    public function getDateByFormat($format)
    {
        $dateModel = $this->dateTimeFactory->create();
        return $dateModel->gmtDate($format);
    }
}

That’s it.

Set custom date and time format in Magento 2 store using any of the above methods and offer excellent user experience.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.