# Several date math questions

**URL:** https://discuss.elastic.co/t/several-date-math-questions/27453
**Category:** Elasticsearch
**Created:** [August 16, 2015, 3:16pm UTC](https://discuss.elastic.co/t/several-date-math-questions/27453 "2015-08-16T15:16:42Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [August 18, 2015, 10:06am UTC](https://discuss.elastic.co/t/several-date-math-questions/27453/3 "2015-08-18T10:06:51Z")

</div>

I can't work out if there are any question from your first post which you still need answers to but I have tried to answer the questions in your second post below. If you still have questions from your first post that you would like answered (or have other questions on date math) let me know.

> [@GordonM](#):
>
> To simply clarify, I am still not sure what /d does exactly. Does it just round down to the beginning of a time period? Or does it round down (backward) to the nearest day?
> 
> If it is 12:01:00 currently
> 
> now/d = 00:00:00now-1h/d = 11:00:00now+1h/d = 12:00:00
> 
> Is this interpretation on the right track?

the `/X` operator (where X is a time period like `d`) will round back in time to the nearest start of that time period. So `/d` will round back to the start of the day, whereas `/M` would round back to the start of the month.

So if it is 2015-08-15 12:01:00 currently:

```auto
now/d = 2015-08-15 00:00:00
now-1h/d = (2015-08-15 11:01:00)/d = 2015-08-15 00:00:00
now+1h/d = (2015-08-15 13:01:00)/d = 2015-08-15 00:00:00
now-13h/d = (2015-08-14 23:01:00)/d = 2015-08-14 00:00:00

now/d-1h = (2015-08-15 00:00:00) - 1h = 2015-08-14 23:00:00
now/d+1h = (2015-08-15 00:00:00) + 1h = 2015-08-15 01:00:00
now/d-13h = (2015-08-15 00:00:00) - 13h = 2015-08-14 11:00:00

```

Does that make sense?

To pick a couple of the questions from your first post:

> [@GordonM](#):
>
> I want to get hits beginning on the first of the current month.

try this:

```json
"filter": {
			"bool": {
				"must": [
					{ "range": { "@timestamp" : { "gte" : "now/M" }}}
				]
			}
		},

```

If now is 2015-08-18 11:00:00 then:

```auto
now/M = 2015-08-01 00:00:00

```

So the above query will match everything from 1st August 2015 onwards

> [@GordonM](#):
>
> I am also having trouble just getting hits from yesterday.

Your second example should work here:

```json
"filter": {
			"bool": {
				"must": [
					{ "range": { "@timestamp" : { "gte" : "now-1d/d" }}},
					{ "range": { "@timestamp" : { "lt" : "now/d" }}}
				]
			}
		},

```

Because if now is 2015-08-18 11:00:00 then:

```auto
now-1d/d = (2015-08-17 11:00:00)/d = 2015-08-17 00:00:00
now/d = 2015-08-18 00:00:00

```

So the problem here could be timezones (timezones are hard). When you ingest your data does it contain a timezone? What is the timezone of your server? What is the timezones of the results when they are displayed (could you show a snippet of some of the erroneous hits?)?

HTH

---

_[View the full topic](https://discuss.elastic.co/t/several-date-math-questions/27453)._
