0

I am having trouble pulling the date out of a datetime in magento.

Currently the date gets called using:

$_formatDate = Mage::app()->getLocale()->getDateTimeFormat(
                Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM
            );
$create_time = Mage::app()->getLocale()
                ->date($_order->getData('created_at'), Varien_Date::DATETIME_INTERNAL_FORMAT)->toString($_formatDate);

I need the date in the format d-m-Y but I can't seem to work it out. I need something like:

$create_date = $create_time->toString('d-m-Y')
1
  • have you tried $create_date = date_format($create_time, 'd-m-Y'); ?
    – John
    Apr 13, 2018 at 6:28

1 Answer 1

2

Try something like this:

$create_time = Mage::app()->getLocale()
        ->date($_order->getData('created_at'), Varien_Date::DATETIME_INTERNAL_FORMAT)->getTimestamp();

This will give you the timestamp and to transform it in the format you like use this:

$created_time = date('d-m-Y', $create_time);

I tested it and it works!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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