Developers often need to work with date and time in Magento 2. Every store has a unique time zone. Therefore, it is essential to know how the time zone works for Magento 2 stores.
For example, if your store delivers the product only after a specific time of the day, you require to get current store date and time in Magento 2 and prepare product delivery schedule according to the time.
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 “the shipment must be done after 3 am only”.
While creating a store, you have to configure Magento 2 stores and times zones and to serve the purpose of time conversion due to the time zone differences, I’ve come up with the solution to get current store date and time in Magento 2.
Steps to Get Current Store Date and Time in Magento 2
- Create Data.php file and use this code.
class Data extends AbstractHelper
public function __construct(
$this->timezoneInterface = $timezoneInterface;
public function getStoreDateTime()
$formatDate = $this->timezoneInterface->formatDate();
// you can also get format wise date and time
$dateTime = $this->timezoneInterface->date()->format('Y-m-d H:i:s');
$date = $this->timezoneInterface->date()->format('Y-m-d');
$time = $this->timezoneInterface->date()->format('H:i');
If you have a query regarding this post, feel free to ask in the Comment section below.
I would like to solve your query.
Do consider sharing this post with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.