# Elasticsearch time to as in via python (timezone)

**URL:** https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340
**Category:** Elasticsearch
**Created:** [November 5, 2020, 1:09am UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340 "2020-11-05T01:09:56Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [November 5, 2020, 1:09am UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/1 "2020-11-05T01:09:56Z")

</div>

I have a wrote small python script where I am reading certain information from Elasticsearch and pushing that back in to ELK.

what I want it to keep what ever date-time I get from ELK. I want to push same as is back in ELK. but it is converting that to UTC and hence my data are skew

for example  
my\_date  
2020-11-01 success monoexec 116477  
2020-11-01 success paraexec 16300

but this my\_date becomes 2020-10-31 19:00.00

How do I keep same date that I received from ELK and put it back to elk (this is new index)

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [November 5, 2020, 1:13am UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/2 "2020-11-05T01:13:02Z")

</div>

Elasticsearch assumes any date that it receives is in UTC. If the python code doesn't include a timezone, you may want to alter it accordingly.

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [November 5, 2020, 1:18am UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/3 "2020-11-05T01:18:05Z")

</div>

yes I know it is converted back in UTC. but I want to save it as is. i.e add timezone

any python guy might know how to do it

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [November 5, 2020, 2:17pm UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/4 "2020-11-05T14:17:36Z")

</div>

I basically want to add timezone=UTC to data I get because when you run DSL or sql query against elasticsearch you get date in UTC format.

but then when you try to put that back in ELK it moves to local time and whole date gets change.

And I am not even worry about hour. I want d/m/yy same as I pulled from ELK to be back in ELK

---

<div class="post-metadata">

### Author: ![KARTHIKEYAN\_THANIKAC](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karthikeyan_thanikac/32/53154_2.png) [@KARTHIKEYAN\_THANIKAC](https://discuss.elastic.co/u/KARTHIKEYAN_THANIKAC)
#### Post date: [November 5, 2020, 4:41pm UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/5 "2020-11-05T16:41:55Z")

</div>

For Your requirement define index pattern for datetime fields, which validates the input data and if input data matchs datefiled format then data will be instered as elatic document

---

<div class="post-metadata">

### Author: ![elasticforme](https://avatars.discourse-cdn.com/v4/letter/e/f05b48/32.png) [@elasticforme](https://discuss.elastic.co/u/elasticforme)
#### Post date: [November 5, 2020, 8:38pm UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/6 "2020-11-05T20:38:34Z")

</div>

ok it is solved.

mytime\_timestamp = datetime.strptime(mytime, "%Y-%m-%d")  
datetime\_obj\_utc = mytime\_timestamp.replace(tzinfo=timezone('Etc/UTC'))  
datetime\_obj\_cst = mytime\_timestamp.replace(tzinfo=timezone('America/Chicago'))

s\_achieved = datetime\_obj\_cst  
s\_achieved\_timezone = datetime\_obj\_utc

now create two index pattern one with s\_achieved time, second one with s\_achieved\_timezone

for kibana use first index pattern  
for sql query use second one.

---

<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: [December 3, 2020, 8:38pm UTC](https://discuss.elastic.co/t/elasticsearch-time-to-as-in-via-python-timezone/254340/7 "2020-12-03T20:38:39Z")

</div>

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