# Date format with timezone offset

**URL:** <https://discuss.elastic.co/t/date-format-with-timezone-offset/231576>\
**Category:** Elasticsearch\
**Created:** [May 7, 2020, 3:17pm UTC](https://discuss.elastic.co/t/date-format-with-timezone-offset/231576 "2020-05-07T15:17:10Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [May 7, 2020, 4:04pm UTC](https://discuss.elastic.co/t/date-format-with-timezone-offset/231576/2 "2020-05-07T16:04:48Z")

</div>

Assuming this is on some late 7.x version, according to the java [the docs](https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html) that we link from our [format docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-date-format.html), five is the magic number in this case:

> **Offset Z** : This formats the offset based on the number of pattern letters. One, two or three letters outputs the hour and minute, without a colon, such as '+0130'. The output will be '+0000' when the offset is zero. Four letters outputs the [full](https://docs.oracle.com/javase/8/docs/api/java/time/format/TextStyle.html#FULL) form of localized offset, equivalent to four letters of Offset-O. The output will be the corresponding localized offset text if the offset is zero. **Five letters outputs the hour, minute, with optional second if non-zero, with colon.** It outputs 'Z' if the offset is zero. Six or more letters throws `IllegalArgumentException` .

This at least works for me on 7.6.2

```auto
DELETE test

PUT /_template/test
{
 	"index_patterns": ["test"],
	"mappings": {
 	  "properties": {
 			"date": { "type": "date", "format": "yyyy-MM-dd HH:mm:ssZZZZZ" }
 		}
 	}
 }
 
PUT /test/_doc/1
{ "date1": "2020-05-07 13:16:44+00:00" }

GET /test/_search
{
  "docvalue_fields": ["date"]
})

```

Formatting is also often weird to me, I keep re-reading those docs and need to try things every time, and zone offsets are especially hard. Hope this helps.

---

_[View the full topic](https://discuss.elastic.co/t/date-format-with-timezone-offset/231576)._
