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:
- Login to admin panel
- Go to Stores > Configuration
- Under Catalog, select catalog
- Expand Date & Time Custom Options
- 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.
- Save configuration
* Custom Date format
const FORMAT_DATE = 'm-d-Y H:i:s';
* @var DateTimeFactory
public function __construct(
$this->dateTimeFactory = $dateTimeFactory;
* Get Current Format date
* @return string
public function getFormatDate(): string
$dateModel = $this->dateTimeFactory->create();
Set custom date and time format in Magento 2 store using any of the above methods and offer excellent user experience.