# How to return day num in Kibana Scripted field

**URL:** https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683
**Category:** Kibana
**Tags:** timelion
**Created:** [March 15, 2022, 6:03am UTC](https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683 "2022-03-15T06:03:26Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![krishray09](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishray09/32/103925_2.png) [@krishray09](https://discuss.elastic.co/u/krishray09)
#### Post date: [March 15, 2022, 6:03am UTC](https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683/1 "2022-03-15T06:03:26Z")

</div>

Hi all, Im using ES query in multiple Timelion charts to compare data for multiple dates. So I used new variables e.x: $u1=-32d, $u2=-69d in below es() query. Can anyone guide me how to use this as a scripted field to be reused in multiple charts instead of changing the dates for each chart everytime.

'''  
$u1='-32d',$u2='-69d',  
.es(index=jobdata-_,metric=sum:MIPS,interval=300s,timefield=int\_starttime\_ts,offset=$u1,q='(jobname.keyword:"xxxxx")').lines(width=1).label(label='U-1'),  
.es(index=jobdata-_,metric=sum:MIPS,interval=300s,timefield=int\_starttime\_ts,offset=$u2,q='(jobname.keyword:"xxxxx")').lines(width=1).label(label='U-2')  
'''

---

<div class="post-metadata">

### Author: ![krishray09](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/krishray09/32/103925_2.png) [@krishray09](https://discuss.elastic.co/u/krishray09)
#### Post date: [April 5, 2022, 2:55am UTC](https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683/2 "2022-04-05T02:55:24Z")

</div>

@matschaffer , @leandrojmp - Any idea or suggestion you can share on this query

---

<div class="post-metadata">

### Author: ![matschaffer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matschaffer/32/95396_2.png) [@matschaffer](https://discuss.elastic.co/u/matschaffer)
#### Post date: [April 5, 2022, 5:18am UTC](https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683/3 "2022-04-05T05:18:55Z")

</div>

Hi @krishray09 - I've never really used timelion, but it looks like you're trying to display the same time series with two different time offsets.

In current kibana releases, the recommended way to do this is with lens time shifting.

[Create visualizations with Lens | Kibana Guide [8.1] | Elastic](https://www.elastic.co/guide/en/kibana/current/lens.html#lens-formulas) includes a one week timeshifted example formula you should be able to work from.

For a predefined shift you don't even need to a formula, but 32 and 96 days are not available as predefined choices so you'll need a formula for that.

 ![Screen_Shot_2022-04-05_at_14_16_58](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e760005c3b8a16ed0279de1e1fa69970a44e7e6.png)

---

<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: [May 3, 2022, 5:19am UTC](https://discuss.elastic.co/t/how-to-return-day-num-in-kibana-scripted-field/299683/4 "2022-05-03T05:19:11Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
