1

I load the following code:

<?php if (isset($item['delivery_eta'])): ?>
<?php $date = DateTime::createFromFormat('m-d-Y', $item['delivery_eta']);
if (!$date) { $date = DateTime::createFromFormat('Y-m-d', $item['delivery_eta']); }
?>
<?php foreach ($this->getOutOfStockItems()->getData() as $item): ?>
    <?php echo $this->getFormatedDate($date->format('Y-m-d'), 'full') ?>
<?php endforeach ?>

This is displaying the date into the following output: Friday 15 December 2017

But now I need to get the php line, that only displays Friday.

How can I achieve that?

I also need the php line for only the day, in this example 15. And also only the month, in this example December.

How can I get these values?

| improve this question | | | | |
1
<?php echo $this->getFormatedDate($date->format('Y-m-d'), 'full')['day'] ?>

EDIT:

Workaround

To just get the date

    <?php $parsedDate= $this->getFormatedDate($date->format('Y-m-d'), 'full') ?>
    <?php echo strtok($parsedDate, " ") ?> // Friday

To parse all your full date separatly

<?php $parsedDate= $this->getFormatedDate($date->format('Y-m-d'), 'full') ?> // Friday 15 December 2017

$parsingDate = explode(" ", $parsedDate);
echo $parsingDate[0]."<br/>"; // Friday
echo $parsingDate[1]."<br/>"; // 15
echo $parsingDate[2]."<br/>"; // December
echo $parsingDate[3]."<br/>"; // 2017
| improve this answer | | | | |
  • Thanks a lot! That is only dispalying "F" instead of "Friday" – JGeer Dec 7 '17 at 14:31
  • Look my update @Henk Z – PЯINCƏ Dec 7 '17 at 14:41
  • Thanks, but that does not work. Because we need to change the date format from 'm-d-Y' to 'Y-m-d', this because the date format inside the attributes. – JGeer Dec 7 '17 at 15:02
  • Look now @Henk Z – PЯINCƏ Dec 7 '17 at 15:19
  • Thanks! But now I need the same for the name of the Month and also the Day of the Month – JGeer Dec 7 '17 at 15:36
0

For only displays Friday.

you need to used this code.

<?php foreach ($this->getOutOfStockItems()->getData() as $item): ?>
<?php echo $this->getFormatedDate($date->format('D'), 'full') ?>
<?php endforeach ?>
| improve this answer | | | | |
  • Thanks for your reply, sadly that does not seem to work. It displays a other date, instead of only Friday. It displays then Wednesday 13 December 2017 instead of Wednesday 3 January 2018. – JGeer Dec 7 '17 at 14:12
  • I update answer, please check that. – Dhiren Vasoya Dec 7 '17 at 14:13
  • Thanks a lot! That still does not seem to work well. That does display also a different date like Friday 8 December 2017 instead of Friday 29 December 2017. – JGeer Dec 7 '17 at 14:15
  • can you tell me $date is object of what? – Dhiren Vasoya Dec 7 '17 at 14:17
  • Sorry that was quite stupid, forgot to paste it into my question. I updated my question. – JGeer Dec 7 '17 at 14:19

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.