# Use date field as time-only field and query question

**URL:** <https://discuss.elastic.co/t/use-date-field-as-time-only-field-and-query-question/8280>\
**Category:** Elasticsearch\
**Created:** [July 2, 2012, 9:08am UTC](https://discuss.elastic.co/t/use-date-field-as-time-only-field-and-query-question/8280 "2012-07-02T09:08:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thorsten\_2](https://avatars.discourse-cdn.com/v4/letter/t/8c91f0/32.png) [@Thorsten\_2](https://discuss.elastic.co/u/Thorsten_2)\
**Post date:** [July 2, 2012, 9:08am UTC](https://discuss.elastic.co/t/use-date-field-as-time-only-field-and-query-question/8280/1 "2012-07-02T09:08:34Z")

</div>

Dear ES,  
I'm trying to work with a time-only field, to represent business hours.

I've set the mapping to 'date' with format 'hour\_minute\_second', so far, so  
good:

```
"open" : {
        "type" : "date",
        "format" : "hour_minute_second"
      },
"close" : {
        "type" : "date",
        "format" : "hour_minute_second"
      },

```

First problem: If a company is opened until midnight, I'd have to save  
'24:00:00' in the field, but that is not possible (not regarded as valid  
time).

Second question, since I'd like to query companies that are opened at the  
moment, how can I build a query that selects all entires where NOW() is  
between field "open" and field "close"?

Thanks for your help

Thorsten

---

<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:21am UTC](https://discuss.elastic.co/t/use-date-field-as-time-only-field-and-query-question/8280/2 "2017-07-06T03:21:51Z")

</div>


