# Ingest date with 12 hour format

**URL:** <https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713>\
**Category:** Elasticsearch\
**Created:** [July 10, 2019, 10:15am UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713 "2019-07-10T10:15:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vijayakumar\_Kannan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijayakumar_kannan/32/34873_2.png) [@Vijayakumar\_Kannan](https://discuss.elastic.co/u/Vijayakumar_Kannan)\
**Post date:** [July 10, 2019, 10:15am UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/1 "2019-07-10T10:15:37Z")

</div>

Trying to extract the date by date processor it's not successful. Still taking the normal timestamp

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
	"processors": [
	  {
	    "grok": {
		   "ignore_missing": true,
		   "field": "message",
		   "patterns": ["""%{GREEDYDATA:date}"""]
			  }
		},	
      {
        "remove" : {
          "field" : "message"
        }
      },
      {
        "date" : {
          "field" : "date",
          "target_field" : "testdate",
          "formats" : ["M/d/yyyy HH:m:s a"],
          "timezone" : "Asia/Kolkata",
          "ignore_failure" : true
        }
      }
		   ]
		   },
   "docs": [
     {
       "_source": {
         "message": """7/9/2019 4:29:55 PM"""
         }
     }
   ]
  }

```

## Result

```auto
{
  "docs" : [
    {
      "doc" : {
        "_index" : "_index",
        "_type" : "_type",
        "_id" : "_id",
        "_source" : {
          "date" : "7/9/2019 4:29:55 PM",
          "testdate" : "2019-07-09T04:29:55.000+05:30"
        },
        "_ingest" : {
          "timestamp" : "2019-07-10T10:11:16.188Z"
        }
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 10, 2019, 10:30am UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/2 "2019-07-10T10:30:05Z")

</div>

This looks correct to:

```auto
"testdate" : "2019-07-09T04:29:55.000+05:30"

```

is indeed a date coming from:

```auto
"date" : "7/9/2019 4:29:55 PM"

```

parsed with `"M/d/yyyy HH:m:s a"`.

What else do you expect?

`timestamp` is just an information (an ingest meta data) which will not be part of your document at the end. It's the date when you ran the ingest pipeline actually.

---

<div class="post-metadata">

**Author:** ![Vijayakumar\_Kannan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijayakumar_kannan/32/34873_2.png) [@Vijayakumar\_Kannan](https://discuss.elastic.co/u/Vijayakumar_Kannan)\
**Post date:** [July 10, 2019, 12:37pm UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/3 "2019-07-10T12:37:17Z")

</div>

Date field is Evening **4 PM** but testdate field is still **04:29:55**

> [@Vijayakumar\_Kannan](#):
>
> "date" : "7/9/2019 4:29:55 PM", "testdate" : "2019-07-09T04:29:55.000+05:30"

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [July 10, 2019, 1:03pm UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/4 "2019-07-10T13:03:44Z")

</div>

Here is an example:

```auto
POST _ingest/pipeline/_simulate
{
  "pipeline": {
    "processors": [
      {
        "date": {
          "field": "date",
          "formats": [
            "M/d/yyyy h:m:s a"
          ]
        }
      }
    ]
  },
  "docs": [
    {
      "_source": {
        "date": "7/9/2019 4:29:55 PM"
      }
    }
  ]
}

```

Don't use `"ignore_failure": true` as this is hiding important error messages.  
Note the change: `HH` is meant for 24 hours. With AM/PM you need to use 12 hours: `h`.

---

<div class="post-metadata">

**Author:** ![Vijayakumar\_Kannan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vijayakumar_kannan/32/34873_2.png) [@Vijayakumar\_Kannan](https://discuss.elastic.co/u/Vijayakumar_Kannan)\
**Post date:** [July 11, 2019, 5:20am UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/5 "2019-07-11T05:20:10Z")

</div>

> [@Vijayakumar\_Kannan](#):
>
> POST \_ingest/pipeline/\_simulate { "pipeline": { "processors": [{ "grok": { "ignore\_missing": true, "field": "message", "patterns": ["""%{GREEDYDATA:date}"""] } }, { "remove" : { "field" : "message" } }, { "date" : { "field" : "date", "target\_field" : "testdate", "formats" : ["M/d/yyyy HH:m:s a"], "timezone" : "Asia/Kolkata", "ignore\_failure" : true } } ] }, "docs": [{ "\_source": { "message": """7/9/2019 4:29:55 PM""" } }] }

Thanks .

---

<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:** [August 8, 2019, 5:20am UTC](https://discuss.elastic.co/t/ingest-date-with-12-hour-format/189713/6 "2019-08-08T05:20:18Z")

</div>

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