# RFC 3339 DateTime in Kirby for Atom feed?

**URL:** https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162
**Category:** Questions
**Tags:** v3
**Created:** [May 29, 2025, 4:10am UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162 "2025-05-29T04:10:44Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 29, 2025, 4:10am UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/1 "2025-05-29T04:10:44Z")

</div>

I’m trying to build my own atom feed from scratch via a template and I’ve pretty much gotten everything to pass validation except for the timestamps.

Here is a screenshot of the Atom validator:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/3X/3/9/392ca864e41c8251168ecc75dd9b784b19a7ab61.png)

It says the date must be in RFC-3339 format which looks like this:

1985-04-12T23:20:50.52Z

From my research, PHP has predefined constants:

```auto
date(DATE_RFC3339);
date(DATE_ATOM);

```

I just can’t figure out how to display this format in Kirby.

I also have my atom feed setup at /feed, but it would be nice if I could have it work as /feed.atom. Is there a straightforward way to add the .atom extension at the end for this url?

Here’s my code for this page in case it helps:

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/3X/a/1/a131d92cb87cf334e0b064bd60bb93ea83a85dce.png)

Appreciate any help! 🙏

---

<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: [May 29, 2025, 5:43am UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/2 "2025-05-29T05:43:24Z")

</div>

Welcome to the Kirby forum!

> [@radiantm3](#):
>
> `DATE_RFC3339`

```auto
<?= $item->date()->toDate(DATE_RFC3339); ?>

```

See also: [$field-\>toDate() | Kirby CMS](https://getkirby.com/docs/reference/templates/field-methods/to-date)

In future posts, please post code as code snippets between three backticks, like so:

 ![backticks](https://europe1.discourse-cdn.com/flex017/uploads/getkirby/original/3X/f/a/fa207d9c7597af6d0f15703cacb309a706f6f165.png).

Thank you!

---

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 29, 2025, 2:09pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/3 "2025-05-29T14:09:29Z")

</div>

Thank you! I will use the code tag next time. I did try your solution initially and thought it wasn’t working because this is the result I get:

```auto
<updated>2025-0-28\</updated>

```

I’m assuming I need to do something else to deal with the escaped character?

---

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 30, 2025, 2:14pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/4 "2025-05-30T14:14:01Z")

</div>

Hoping for an answer on this one! 🙏

---

<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: [May 30, 2025, 2:50pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/5 "2025-05-30T14:50:39Z")

</div>

Hm, don’t know and can’t test, because just on phone until Monday

---

<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: [May 30, 2025, 3:04pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/6 "2025-05-30T15:04:14Z")

</div>

Can you try it with `"Y-m-d\\TH:i:sP"`? The `toDate` method expects a string so maybe that’s what fails when passing the constant.

---

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 30, 2025, 6:59pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/7 "2025-05-30T18:59:40Z")

</div>

I think I know why this is happening. I have a date set for my posts, but no time. 🤦‍♂️ I will try to get that sorted and report back. Sorry!

---

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 30, 2025, 7:18pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/8 "2025-05-30T19:18:21Z")

</div>

Ok I added the time as well, but still having the same issue.

This is now in my txt files:

```auto
Date: 2025-04-04 00:00:00

```

Here are the pages I’m filtering for the atom feed:

```auto
<?php
	$blog = $pages->find('blog')->children()->listed()->sortBy(function ($page){return $page->date();}, 'asc')->limit(10);
	$kirby->response()->type('application/atom+xml');
?>

```

If I just use this:

```auto
<updated><?= $blog->last()->date(); ?></updated>

```

Here is the output:

```auto
<updated>2025-04-04 00:00:00</updated>

```

If I do this (or : “Y-m-d\TH:i:sP”)

```auto
<updated><?= $blog->last()->date()->toDate(DATE_RFC3339); ?></updated>

```

Here is the output:

```auto
<updated>2025-0-4\</updated>

```

---

<div class="post-metadata">

### Author: ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)
#### Post date: [May 31, 2025, 3:55pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/9 "2025-05-31T15:55:12Z")

</div>

Hm, I suspect you are using the `date.handler` option with the `intl` value, which then makes Kirby use PHP’s `Intl` extension for internationalized date formatting. This would explain why some parts of the date are formatted (with different values) and the backslash survives the formatting into the output.

You can either switch to the basic PHP `date` handler, or use the following format with `intl`:

```php
<updated><?= $blog->last()->date()->toDate("y-MM-dd'T'HH:mm:ssxxx"); ?></updated>

```

You can find more about this in the reference:

> **[date](https://getkirby.com/docs/reference/system/options/date)**
>
> Setup date handling

---

<div class="post-metadata">

### Author: ![radiantm3](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/radiantm3/32/15688_2.png) [@radiantm3](https://forum.getkirby.com/u/radiantm3)
#### Post date: [May 31, 2025, 9:21pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/10 "2025-05-31T21:21:48Z")

</div>

> [@lukasbestle](#):
>
> `"y-MM-dd'T'HH:mm:ssxxx")`

That seems to be it! Thank you!

---

<div class="post-metadata">

### Author: ![fvsch](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/fvsch/32/15908_2.png) [@fvsch](https://forum.getkirby.com/u/fvsch)
#### Post date: [June 1, 2025, 9:16am UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/11 "2025-06-01T09:16:45Z")

</div>

## Date formatting

I’m using this in my Atom and JSON feed templates:

```php
$published = $page->content()->get('published')->toDate();
echo date(DateTimeInterface::W3C, $published);

```

The `DateTimeInterface::W3C` constant is defined like this:

```php
public const string W3C = "Y-m-d\\TH:i:sP";

```

## `.atom` extension in URL

> I also have my atom feed setup at `/feed`, but it would be nice if I could have it work as `/feed.atom`. Is there a straightforward way to add the `.atom` extension at the end for this url?

You can use [Content representations](https://getkirby.com/docs/guide/templates/content-representations).

On my own site I’ve implemented this by having a `content/feed/feed.txt` page, and then creating the following templates:

- `site/templates/feed.php` ← not used but required!
- `site/templates/feed.json.php` ← renders a [JSON Feed](https://www.jsonfeed.org/)
- `site/templates/feed.xml.php` ← renders an Atom feed

The `feed.php` template is empty:

```php
<?php
/**
 * This template has to exist so that the content representation templates
 * (feed.xml.php and feed.json.php) are used by Kirby.
 * More info: https://getkirby.com/docs/guide/templates/content-representations
 */

```

- Loading `/feed.json` will render the `content/feed/feed.txt` page with the `site/templates/feed.json.php` template.
- Loading `/feed.xml` will render the `content/feed/feed.txt` page with the `site/templates/feed.xml.php` template. (I believe you could use any extension, so `.atom` instead of `.xml` might work too.)
- Loading `/feed` will render the `content/feed/feed.txt` page with the `site/templates/feed.php` template, i.e. it will render a blank page. You could create a redirect in your site’s routes or even from the template itself to redirect to `/feed.atom` instead.

I think I’m using the default `text/xml` content-type for `/feed.xml`, but I could add some code to send a `content-type: application/atom+xml` header instead.

---

<div class="post-metadata">

### Author: ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)
#### Post date: [June 1, 2025, 3:56pm UTC](https://forum.getkirby.com/t/rfc-3339-datetime-in-kirby-for-atom-feed/34162/12 "2025-06-01T15:56:31Z")

</div>

Adding to that: You can also create a `feed.atom.php` template (instead of `feed.xml.php`) to create a content representation at `/feed.atom`.

To set the content type header, use:

```php
$kirby->response()->type('application/atom+xml');

```

See:

> **[Content representations](https://getkirby.com/docs/guide/templates/content-representations#representation-types)**
>
> Content representations allow you to output the content in different formats. Be it JSON for your frontend JS library of choice or to use Kirby as an API for other tools, an automatic RSS feed …
