# Sort according to day not hour

**URL:** <https://forum.opensearch.org/t/sort-according-to-day-not-hour/20006>\
**Category:** OpenSearch\
**Created:** [June 26, 2024, 7:02am UTC](https://forum.opensearch.org/t/sort-according-to-day-not-hour/20006 "2024-06-26T07:02:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![m\_pahlevanzadeh](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/m_pahlevanzadeh/32/7468_2.png) [@m\_pahlevanzadeh](https://forum.opensearch.org/u/m_pahlevanzadeh)\
**Post date:** [June 26, 2024, 7:02am UTC](https://forum.opensearch.org/t/sort-according-to-day-not-hour/20006/1 "2024-06-26T07:02:29Z")

</div>

When I see my data and timestamp field, sort of them are corresponding to hour not date. How can tell to opensearch store according to date?

---

<div class="post-metadata">

**Author:** ![Mantas](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@Mantas](https://forum.opensearch.org/u/Mantas)\
**Post date:** [June 26, 2024, 9:56am UTC](https://forum.opensearch.org/t/sort-according-to-day-not-hour/20006/2 "2024-06-26T09:56:44Z")

</div>

Hi @m_pahlevanzadeh,

You can sort with:

```auto
"sort": [
    {
      "date": {
        "order": "desc"
      }
    }
  ]

```

or if you want more control you can always use painless something like:

```auto
 "sort": [
    {
      "_script": {
        "type": "number",
        "script": {
          "source": "doc[\"<date_field>\"].value.toInstant().toEpochMilli()", # this should convert to milliseconds for further sorting..
          "lang": "painless"
        },
        "order": "desc"

```

best,  
mj
