# conditional variables depending on time

**URL:** <https://forum.ansible.com/t/conditional-variables-depending-on-time/30014>\
**Category:** Ansible Project\
**Created:** [March 28, 2019, 8:17pm UTC](https://forum.ansible.com/t/conditional-variables-depending-on-time/30014 "2019-03-28T20:17:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![olyx11](https://avatars.discourse-cdn.com/v4/letter/o/3e96dc/32.png) [@olyx11](https://forum.ansible.com/u/olyx11)\
**Post date:** [March 28, 2019, 8:17pm UTC](https://forum.ansible.com/t/conditional-variables-depending-on-time/30014/1 "2019-03-28T20:17:31Z")

</div>

I am trying to output what shift an event has happened depending on the time of day, but keep running into errors or getting nothing back.

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [March 29, 2019, 6:03pm UTC](https://forum.ansible.com/t/conditional-variables-depending-on-time/30014/2 "2019-03-29T18:03:34Z")

</div>

There are two reason this will not work.  
The second shift will overwrite the first shift and the third shift will overwrite the second shift.  
ansible\_date\_time.time is a string an you are comparing string, since time compare and string compare is completely different thing, this will not work as you would like.

---

<div class="post-metadata">

**Author:** ![olyx11](https://avatars.discourse-cdn.com/v4/letter/o/3e96dc/32.png) [@olyx11](https://forum.ansible.com/u/olyx11)\
**Post date:** [March 29, 2019, 9:25pm UTC](https://forum.ansible.com/t/conditional-variables-depending-on-time/30014/3 "2019-03-29T21:25:55Z")

</div>

I figured it out by using set\_fact and when for the conditionals. Thanks for the reply.
