# Does date-format of ES7.5.2 not support YYYY?

**URL:** https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787
**Category:** Elasticsearch
**Created:** [December 7, 2023, 7:39am UTC](https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787 "2023-12-07T07:39:13Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![MiuNice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miunice/32/128884_2.png) [@MiuNice](https://discuss.elastic.co/u/MiuNice)
#### Post date: [December 7, 2023, 7:39am UTC](https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787/1 "2023-12-07T07:39:13Z")

</div>

I created a field named "created" in the index as shown below:

```auto
"created": {
    "type": "date",
    "format": "YYYY-MM-dd'T'HH:mm:ss'Z'"
}

```

When I used the range method for querying, I got unexpected results. There is a document in Elasticsearch (ES) with a value of "2023-05-24T06:00:33Z" for the "created" field. However, when I queried with "range lt 2024-01-01T00:00:00Z", it failed to retrieve that document correctly.

To investigate the issue, I added the "explain" parameter to the query. Here is my statement:

```auto
{
  "explain": true,
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "created": {
              "lt": "2023-05-25T00:00:00Z"
            }
          }
        }
      ]
    }
  }
}

```

The unexpected result in the returned explanation is: "created:[-9223372036854775808 TO 12441599999]". It appears that the value 12441599999 corresponds to 1970-05-25 07:59:59.

However, when I changed "YYYY" to "yyyy" in the mappings, everything worked correctly.

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [December 7, 2023, 7:46am UTC](https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787/2 "2023-12-07T07:46:11Z")

</div>

Yes, there is a differenece between `YYYY` and `yyyy` in Java date formats, as explained in [this blog post](https://dangoldin.com/2019/01/06/javas-simpledateformat-yyyy-vs-yyyy/).

---

<div class="post-metadata">

### Author: ![MiuNice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/miunice/32/128884_2.png) [@MiuNice](https://discuss.elastic.co/u/MiuNice)
#### Post date: [December 7, 2023, 7:54am UTC](https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787/3 "2023-12-07T07:54:02Z")

</div>

TKS.  
I read the above blog and the problem he mentioned only appears at the beginning and end of the year. In fact, the problem I have is that I can't parse the year when I range.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [January 4, 2024, 7:54am UTC](https://discuss.elastic.co/t/does-date-format-of-es7-5-2-not-support-yyyy/348787/4 "2024-01-04T07:54:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
