I'm creating a shipping module, and I need to get current store time and date at the time. in my requirement, I need to check if the day is Friday or not. Then after that, I need to check if time is earlier than 3.30pm (15.30) or not.

I've looked into \Magento\Framework\Stdlib\DateTime\DateTime $datetime but it doesn't provide what I'm looking for.

How can I get store date/time and format it for my requirement? Please help


Use this to get store date and time:-

public function __construct(Context $context,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone,
    $this->timezone = $timezone;
public function execute()
    $date = $this->timezone->date();
    $currentdate = $date->format('d/m/y');     
    $time = $date->format('H:i:s A');  


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.