Clean way to customize date format? (ex: October 13, 2018)


I’m trying to customize the date on some blog posts. When the date gets inputed in the panel, it looks like 10/13/2018 but I’d like it to display on the web page as October 13, 2018.

Currently, I’m doing it by brute force with a lot of if and else if statements but I’m wondering if there’s a cleaner way to do this?

<?php if($page->date('n') == 1): ?>
    <p>January <?= $page->date('d') ?>, <?= $page->date('Y') ?></p>
<?php elseif($page->date('n') == 2): ?>
    <p>February <?= $page->date('d') ?>, <?= $page->date('Y') ?></p>
<?php elseif($page->date('n') == 3): ?>
    <p>March <?= $page->date('d') ?>, <?= $page->date('Y') ?></p>
<?php elseif($page->date('n') == 4): ?>
    <p>April <?= $page->date('d') ?>, <?= $page->date('Y') ?></p>

You can format the date like this:

<?= $page->date('F d, Y') ?>

If you need to localize, use the strftime date handler with corresponding format in your config.

1 Like

Sweet! Thanks for helping out a newbie.