# Converting Date Type To String Type

**URL:** https://discuss.elastic.co/t/converting-date-type-to-string-type/47514
**Category:** Kibana
**Created:** [April 15, 2016, 2:47pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514 "2016-04-15T14:47:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![saba\_soltani](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@saba\_soltani](https://discuss.elastic.co/u/saba_soltani)
#### Post date: [April 15, 2016, 2:47pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/1 "2016-04-15T14:47:14Z")

</div>

Hi,

In my dataset, there is a field which type is date with "dddd" format (Day of Week).  
Can I create a scripted field in kibana which contains the value of this field but in the form of string?

For example :  
The date field is Start\_Date and it equals to Wednesday. How to create "Day Of Week" field (string type)  
which contains exactly "Wednesday" but as a string?

Regards,

---

<div class="post-metadata">

### Author: ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)
#### Post date: [April 15, 2016, 4:03pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/2 "2016-04-15T16:03:51Z")

</div>

Can you share your index's mapping, please, specifically for the `Start_Date` field?

---

<div class="post-metadata">

### Author: ![saba\_soltani](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@saba\_soltani](https://discuss.elastic.co/u/saba_soltani)
#### Post date: [April 15, 2016, 8:05pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/3 "2016-04-15T20:05:51Z")

</div>

I hope that I share right thing ( actually I have recently started working with kibana and elasticsearch). Is it what you mean?

 ![](https://us1.discourse-cdn.com/elastic/original/2X/8/8299364a79ffba7fa8501fc4d3a3215d0d7673a4.jpg)

---

<div class="post-metadata">

### Author: ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)
#### Post date: [April 15, 2016, 9:34pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/4 "2016-04-15T21:34:48Z")

</div>

I was actually referring to the mapping for the index in Elasticsearch ([https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)) but what you have shared is helpful too.

So it looks like you have already formatted the `Start_Date` field with `dddd` in Kibana. Why do you need another field that contains the same value? What is your end goal here? Knowing that it might be easier to recommend the right approach.

---

<div class="post-metadata">

### Author: ![saba\_soltani](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@saba\_soltani](https://discuss.elastic.co/u/saba_soltani)
#### Post date: [April 15, 2016, 10:25pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/5 "2016-04-15T22:25:18Z")

</div>

Actually, I want to count (unique count) of an **string field** (for example unique count of customer or unique count of Id ) per day of week during a specific time.

And when I am using this field as "Term aggregation" for X-Axis ( because I want to visualize how many customers will be in different week days in order to compare them with each other) , and set "Order By : Unique count of customer" and also order same as below (7 days of week):  
 ![](https://us1.discourse-cdn.com/elastic/original/2X/6/6a08ceaaf71a94769bdd09f51769c4d8df886785.jpg)

The result will be :

 ![](https://us1.discourse-cdn.com/elastic/original/2X/f/f5df49fc46eacb9a0e673175f3846b47a0a37a81.jpg)

Logically this aggregation shows the first 7 days with highest amount of customer and as you can see I have more than one **Wednesday** (I understand completely the result).

Finally 🙂 I want to have 7 bars each belongs to each day of week ( Sunday , Monday ,...) and the height of bars shows sum of customers in each week day during a specific period of time. Then I think I need to consider **Start\_Date** as string in order to solve my problem ( I don't have any vision about any other possibilities)

Thank you so much for your response,

---

<div class="post-metadata">

### Author: ![shaunak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shaunak/32/6643_2.png) [@shaunak](https://discuss.elastic.co/u/shaunak)
#### Post date: [April 15, 2016, 10:48pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/6 "2016-04-15T22:48:00Z")

</div>

I think the only way to do this is to preprocess your data before indexing. For each document, figure out the day of the week, set it as a new field in the document, and then index the document in Elasticsearch.

---

<div class="post-metadata">

### Author: ![saba\_soltani](https://avatars.discourse-cdn.com/v4/letter/s/91b2a8/32.png) [@saba\_soltani](https://discuss.elastic.co/u/saba_soltani)
#### Post date: [April 15, 2016, 10:56pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/7 "2016-04-15T22:56:35Z")

</div>

Thank you so much for your quick response  
I really appriciate it

---

<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: [July 6, 2017, 1:55pm UTC](https://discuss.elastic.co/t/converting-date-type-to-string-type/47514/8 "2017-07-06T13:55:58Z")

</div>


