# Multiple date fields

**URL:** <https://forum.getkirby.com/t/multiple-date-fields/14142>\
**Category:** Questions\
**Tags:** v3\
**Created:** [May 8, 2019, 4:13pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142 "2019-05-08T16:13:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon3573533](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anon3573533](https://forum.getkirby.com/u/anon3573533)\
**Post date:** [May 8, 2019, 4:13pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/1 "2019-05-08T16:13:02Z")

</div>

I’m trying to use multiple dates fields like this:

```auto
    date:
      label: Date
      type: date
    update:
      label: Update
      type: date

<time datetime="<?= $item->date()->toDate('%d.%m.%Y') ?>"><?= $item->date()->toDate('%d.%m.%Y') ?></time> 
       
<span>Updated: </span><time datetime="<?= $item->update()->toDate('%d.%m.%Y') ?>"><?= $item->update()->toDate('%d.%m.%Y') ?></time>

```

But _update_ is not shown. Is it possible to use multiple dates ?  
Thank you.

---

<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 8, 2019, 4:28pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/2 "2019-05-08T16:28:18Z")

</div>

Yes, rename it to something else if you don’t want to update the page instead.

* * *

Your friendly 🤖

---

<div class="post-metadata">

**Author:** ![anon3573533](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anon3573533](https://forum.getkirby.com/u/anon3573533)\
**Post date:** [May 8, 2019, 4:44pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/3 "2019-05-08T16:44:39Z")

</div>

^^ right it works better like this…  
Your friendly 🤯

Can I take this oportunity to ask how I could include the update date in loop sortBy date desc?  
The idea is to use the update date instead of date if it used.  
Or maybe it is better to open a new topic?

---

<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 8, 2019, 4:52pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/4 "2019-05-08T16:52:34Z")

</div>

I’d create a page model that returns either one or the other, then use that for sorting.

```auto
<?php

class WhateverPage extends Page {
  
    public function sortDate()
    {
        return $this->update()->isNotEmpty() ? $this->update()->toDate('%d.%m.%Y') : $this->date()->toDate('%d.%m.%Y');
    }

}

```

In template:

```auto
$sortedArticles = $page->children()->sortBy('sortDate');

```

* * *

🤖

---

<div class="post-metadata">

**Author:** ![anon3573533](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anon3573533](https://forum.getkirby.com/u/anon3573533)\
**Post date:** [May 8, 2019, 5:18pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/5 "2019-05-08T17:18:56Z")

</div>

thank you and sorry, it does not work. Order of articles is mixed and sort by asc or desc have no effect. Maybe all _‘publisedupdate’_ fields should not be left empty ?

---

<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 8, 2019, 5:29pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/6 "2019-05-08T17:29:33Z")

</div>

Ah, maybe it doesn’t work with the formatting, either remove that or change it to `%Y%m%d`.

---

<div class="post-metadata">

**Author:** ![anon3573533](https://avatars.discourse-cdn.com/v4/letter/a/848f3c/32.png) [@anon3573533](https://forum.getkirby.com/u/anon3573533)\
**Post date:** [May 8, 2019, 5:42pm UTC](https://forum.getkirby.com/t/multiple-date-fields/14142/7 "2019-05-08T17:42:42Z")

</div>

Unfortunatly not, my model uses date a first time for others needs, maybe that breacks something ?

```auto
<?php

class NewPage extends Page
{

  public function peryear()
  {
    return $this->date()->toDate('%Y');
  }
  
    public function sortDate()
  {
    return $this->publisedupdate()->isNotEmpty() ? $this->publisedupdate()->toDate('%Y%m%d') : $this->date()->toDate('%Y%m%d');
  }

 

}

```
