0

I want to display a specific attribute only when the set time is not passed. Therefore I created the following code:

<?php $dateFrom = Mage::app()->getLocale()->storeTimeStamp(); $dateTo = $_product->getData('actie_datum_eind');?>
<?php if (Mage::app()->getLocale()->isStoreDateInInterval($store, $dateFrom, $dateTo)) : ?>
    <div class="product-sale-label custom"><?php echo $this->htmlEscape($_product->getData('actie_label')); ?></div>
<?php endif;?>

But does not work, the label is not displayed.

When I echo both values, I get the following results:

<?php echo $_product->getData('actie_datum_eind')?><br>
<?php echo Mage::app()->getLocale()->storeTimeStamp()?>

That results in the following:

2017-10-04 00:00:00
1505465811

The results of:

<?php echo $dateFrom?><br>
<?php echo $dateTo?>

Are:

1505465811
2017-10-04 00:00:00

What am I missing here?

2
  • can you please tell me what do you get in $dateFrom , $dateTo and $store ?? Sep 14, 2017 at 18:50
  • @AbhishekPanchal Thanks, I just update my question with the values.
    – JGeer
    Sep 15, 2017 at 6:56

2 Answers 2

0

Magento 2

Proper way

use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
/**
* @var TimezoneInterface
*/
protected $localeDate;

public function __construct(
    TimezoneInterface $localeDate
) {
   $this->localeDate = $localeDate;
}

$this->localeDate->isScopeDateInInterval($store,$FromDate,$ToDate);
2
  • Thanks for your reply. I tried that but that does not seem to work. I am running Magento 1.9. I get a fatal error.
    – JGeer
    Sep 14, 2017 at 18:10
  • I think you recently mention that its for Magento 1.9. Let me update my answer. I already mentioned that its for Magento 2. Sep 14, 2017 at 18:44
0
<?php echo $_product->getData('actie_datum_eind') ?> //2017-10-04 00:00:00, your attribute value.

<?php $date = new DateTime();
$date->setTimezone(new DateTimezone('Europe/Paris'));
echo $date->format('Y-m-d h:i:s'); ?> //2017-09-15 09:55:59, the actual date time.

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.