# How to apply a date format to results from a query for date fields

**URL:** <https://discuss.elastic.co/t/how-to-apply-a-date-format-to-results-from-a-query-for-date-fields/7335>\
**Category:** Elasticsearch\
**Created:** [April 15, 2012, 2:26am UTC](https://discuss.elastic.co/t/how-to-apply-a-date-format-to-results-from-a-query-for-date-fields/7335 "2012-04-15T02:26:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pulkitsinghal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pulkitsinghal/32/802_2.png) [@pulkitsinghal](https://discuss.elastic.co/u/pulkitsinghal)\
**Post date:** [April 15, 2012, 2:26am UTC](https://discuss.elastic.co/t/how-to-apply-a-date-format-to-results-from-a-query-for-date-fields/7335/1 "2012-04-15T02:26:43Z")

</div>

Lets say that a date is stored in a format such that the result comes back  
in JSON as:  
{  
startDate: 959904000000  
}

Is there any way to specify a transformation to a date format like YEAR in  
the query itself?  
Sp that the result coming back which may be stored on ES as 959904000000  
... will be shown in the returned JSON as the year 2005?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [April 17, 2012, 8:13am UTC](https://discuss.elastic.co/t/how-to-apply-a-date-format-to-results-from-a-query-for-date-fields/7335/2 "2012-04-17T08:13:12Z")

</div>

You mean you index it as startDate: 959904000000? You could install use a  
script field to get hte value and munge it how you like  
[Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/search/script-fields.html).

On Sun, Apr 15, 2012 at 5:26 AM, pulkitsinghal [pulkitsinghal@gmail.com](mailto:pulkitsinghal@gmail.com)wrote:

> Lets say that a date is stored in a format such that the result comes back  
> in JSON as:  
> {  
> startDate: 959904000000  
> }
> 
> Is there any way to specify a transformation to a date format like YEAR in  
> the query itself?  
> Sp that the result coming back which may be stored on ES as 959904000000  
> ... will be shown in the returned JSON as the year 2005?

---

<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, 3:32am UTC](https://discuss.elastic.co/t/how-to-apply-a-date-format-to-results-from-a-query-for-date-fields/7335/3 "2017-07-06T03:32:20Z")

</div>


