# Kirby gets the date right, but not the time

**URL:** <https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553>\
**Category:** Questions\
**Tags:** v2\
**Created:** [July 7, 2015, 7:09pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553 "2015-07-07T19:09:53Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 7, 2015, 7:09pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/1 "2015-07-07T19:09:53Z")

</div>

Hi there,

I’m new around here and in many ways still inexperienced, so please bear with me.

I’m trying to set up a blog with the latest version of Kirby. The blog requires a proper way to show the date and time the entry was posted. I haven’t touched the respective Kirby fields.

The theme always gets the date right, but not the time, which remains at midnight. Within the panel, the correct time is given (it’s a fairly odd one, not midnight).

I have a RSS feed as well, which also sticks to midnight, so I don’t think the theme has to do with the issue. Or does it?

Does anyone have a clue where to look at?

Many thanks in advance for your help!

---

<div class="post-metadata">

**Author:** ![Jan](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/jan/32/314_2.png) [@Jan](https://forum.getkirby.com/u/Jan)\
**Post date:** [July 7, 2015, 7:52pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/2 "2015-07-07T19:52:53Z")

</div>

Which theme are you using?

---

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 7, 2015, 8:02pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/3 "2015-07-07T20:02:30Z")

</div>

I forgot the name. It’s a theme that worked with Kirby v1 only. I customized it up to the point that almost everything was rewritten.

This is how the (allegedly) important part of the theme is written:

```
<?php $articles = $page->children()->visible()->flip()->paginate(5) ?>

```

 \<?php foreach($articles as $article): ?\>

```
    <div class="post">
        <div class="post-meta"><?=$article->date('d.m.Y, G:i')?></div>
        <h3 class="post-title"><a href="<?=$article->url()?>"><?=$article->title()?></a></h3>
        <p><?php echo excerpt($article->text(), 350) ?></p>
    </div>

```

\<?php endforeach ?\>

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 7, 2015, 8:04pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/4 "2015-07-07T20:04:57Z")

</div>

How do you enter the date and time in the text file? Is that via a date field, or date and time fields?

---

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 7, 2015, 8:15pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/5 "2015-07-07T20:15:37Z")

</div>

Ah, good question! As far as time is concerned, I have added a [blueprint](http://getkirby.com/docs/cheatsheet/panel-fields/time), which results in separate fields on the panel for the date and the time. Now, as soon I write a blog entry, the text file includes this:

```
Date: 2015-06-15

----

Time: 18:54

```

The blog itself would show everything as expected if the time was added to the “Date:” section:

```
Date: 2015-06-15 18:54

```

How do I get the blueprint to create the blog entry correctly?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 7, 2015, 8:38pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/6 "2015-07-07T20:38:01Z")

</div>

You need those two separate fields, that is correct. But in your template, you only call the date, which does not contain the time or is rather set to midnight. To show the date, simply echo the time field:

```php
<?php echo $article->time() ?>

```

---

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 7, 2015, 8:48pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/7 "2015-07-07T20:48:15Z")

</div>

Amazing, it’s as easy as this, thank you! Really appreciate your quick and competent help, guys!

The only thing left to correct would be the feed, which is generated by Bastian’s plugin. Where am I to edit either the [feed.php](https://github.com/getkirby/plugins/blob/master/feed/feed.php) and/or the [template.php](https://github.com/getkirby/plugins/blob/master/feed/template.php)?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 7, 2015, 9:03pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/8 "2015-07-07T21:03:22Z")

</div>

You need to change lines 8 and 20 in the template, instead of

```php
$item->date('r', $datefield);

```

echo the separate elements separately: [http://php.net/manual/de/function.date.php](http://php.net/manual/de/function.date.php)

---

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 7, 2015, 9:17pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/9 "2015-07-07T21:17:39Z")

</div>

Not sure whether I really got this, as PHP is not my strong suit, but here goes nothing:

Line 8:

```
<lastBuildDate><?php echo date('r', $modified) ?><?php echo time('r', $modified) ?></lastBuildDate>

```

Line 20:

```
<pubDate><?php echo $datefield == 'modified' ? $item->modified('r') : $item->date('r', $datefield) ?><?php echo $timefield == 'modified' ? $item->modified('r') : $item->time('r', $timefield) ?></pubDate>

```

If I apply the changes, the date itself is turned back by nine days, while the time itself is a few hours off, indicating an incorrect time zone.

---

<div class="post-metadata">

**Author:** ![insintesi](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/insintesi/32/5256_2.png) [@insintesi](https://forum.getkirby.com/u/insintesi)\
**Post date:** [July 10, 2015, 12:27am UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/10 "2015-07-10T00:27:31Z")

</div>

I finally came up with the solution, thanks to being sleep-deprived, which provided a much-needed sense of clarity. Aww, you know that!

In the feed.php, I have defined a new default:

```
'timefield' => 'time',

```

This ensures that a separate field for the time within a blog post can be processed properly.

Now, looking at the template.php, line 8 does not need to be rewritten. It apparently generates the information when the feed itself was refreshed.

Line 20, however, is key. It fetches the information from the date field of the blog post and displays it in accordance to RFC 2822 ([example: Thu, 21 Dec 2000 16:01:07 +0200](http://php.net/manual/de/function.date.php)). All I had to do is rebuild this structure piece by piece. This allows me to jump to another echo (if that makes sense), from date to time:

```
<pubDate><?php echo $datefield == 'modified' ? $item->modified('D, d M Y') : $item->date('D, d M Y', $datefield) ?> <?php echo $timefield == 'modified' ? $item->modified('H:i:s O') : $item->time('H:i:s O', $timefield) ?></pubDate>

```

This, in fact, works wonderfully. Wow.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [July 10, 2015, 6:12am UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/11 "2015-07-10T06:12:43Z")

</div>

👍 That’s exactly what I meant. But I had another idea, just haven’t had the time to test this, i.e. using a page model to combine both date and time fields into a single field value and then go from there.

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:17pm UTC](https://forum.getkirby.com/t/kirby-gets-the-date-right-but-not-the-time/1553/12 "2025-02-06T17:17:02Z")

</div>


