# Sortby date created image

**URL:** <https://forum.getkirby.com/t/sortby-date-created-image/28470>\
**Category:** Questions\
**Created:** [April 28, 2023, 9:21am UTC](https://forum.getkirby.com/t/sortby-date-created-image/28470 "2023-04-28T09:21:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rapsli](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rapsli/32/12891_2.png) [@rapsli](https://forum.getkirby.com/u/rapsli)\
**Post date:** [April 28, 2023, 9:21am UTC](https://forum.getkirby.com/t/sortby-date-created-image/28470/1 "2023-04-28T09:21:45Z")

</div>

I’m trying to sort by dateCreated of the image. There is though not explicit field that would store this information, rather it’s in the binary field it-self:

```auto
<?php foreach ($site->find('projekte')->children()->images()->filterBy('category', $page->uri(), ',')->sortBy('dateCreated', 'desc') as $img): ?>

      <div class="col-lg-6 p-3 p-xl-5">
       <div class="portfolio-image">
            <img class="img-fluid w-100 " src="<?= $img->resize(600)->url() ?>" alt="<?= $img->alt() ?>">
       </div>
      </div>

    <?php endforeach ?>

```

Unfortunately this doesn’t have any effect. Do I have to explicitely store that information in a field?

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [April 28, 2023, 9:34am UTC](https://forum.getkirby.com/t/sortby-date-created-image/28470/2 "2023-04-28T09:34:31Z")

</div>

`dateCreated` doesn’t seem to be a [default file method](https://getkirby.com/docs/reference/#file), there is [`modified`](https://getkirby.com/docs/reference/objects/cms/file/modified), but that does something slightly different.

So yes, you’d have to create a field for that, or you could create a [fileMethod plugin](https://getkirby.com/docs/reference/plugins/extensions/file-methods) that retrieves that information from somewhere (like the exif data).

---

<div class="post-metadata">

**Author:** ![rasteiner](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rasteiner/32/4788_2.png) [@rasteiner](https://forum.getkirby.com/u/rasteiner)\
**Post date:** [April 28, 2023, 10:52am UTC](https://forum.getkirby.com/t/sortby-date-created-image/28470/3 "2023-04-28T10:52:24Z")

</div>

Something like:

**/site/plugins/file-methods/index.php**

```php
<?php 

use Kirby\Cms\App as Kirby;

Kirby::plugin('my/plugin', [
    'fileMethods' => [
        'dateCreated' => function () {
           $root = $this->root();

           // search exif data
           $ifd0 = @exif_read_data($root, 'IFD0');
           if($date = $ifd0['DateTime'] ?? false) return strtotime($date);

           // try ctime (might work on windows)
           if($date = filectime($root)) return $date;

           // fallback to mtime
           return $this->modified();
        }
    ]
]);

```

---

<div class="post-metadata">

**Author:** ![rapsli](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/rapsli/32/12891_2.png) [@rapsli](https://forum.getkirby.com/u/rapsli)\
**Post date:** [April 28, 2023, 11:07am UTC](https://forum.getkirby.com/t/sortby-date-created-image/28470/4 "2023-04-28T11:07:52Z")

</div>

thanks. I went with modified. That’s good enough.
