# Ansible date / time variables not found

**URL:** <https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364>\
**Category:** Ansible Project\
**Created:** [May 29, 2014, 3:52pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364 "2014-05-29T15:52:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_Cholakian1](https://avatars.discourse-cdn.com/v4/letter/a/3da27b/32.png) [@Andrew\_Cholakian1](https://forum.ansible.com/u/Andrew_Cholakian1)\
**Post date:** [May 29, 2014, 3:52pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364/1 "2014-05-29T15:52:24Z")

</div>

I’ve got a particularly vexing bug wrt the date / time helpers. Running the following:

- debug: “var=ansible\_date\_time[‘year’]”

Does not give me the current year, the variable remains uninterpolated. I’ve tried various permutations of quoting, to no avail. The debug output suspiciously drops a leading [, making me think there’s a bug in the ansible internals when parsing this. Here’s the debug output:

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [May 29, 2014, 3:57pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364/2 "2014-05-29T15:57:32Z")

</div>

You probably need to change your debug task to look like 1 of the three examples:

- debug: var=ansible\_date\_time.year

- debug:  
var: ansible\_date\_time[‘year’]

- debug:  
var: ansible\_date\_time.year

---

<div class="post-metadata">

**Author:** ![Michael\_Peters](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@Michael\_Peters](https://forum.ansible.com/u/Michael_Peters)\
**Post date:** [May 29, 2014, 5:12pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364/3 "2014-05-29T17:12:52Z")

</div>

Just to clarify, this is because the "[" is part of YAML and is not  
getting parsed as you're expecting. You could probably also just quote  
the whole line.

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [May 29, 2014, 5:20pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364/4 "2014-05-29T17:20:31Z")

</div>

All of the above should work, I’d have to play around with it to see what’s going on but it does seem like there’s some quote mangling in the debug module that may need to be fixxored.

–Michael

---

<div class="post-metadata">

**Author:** ![Andrew\_Cholakian](https://avatars.discourse-cdn.com/v4/letter/a/ee59a6/32.png) [@Andrew\_Cholakian](https://forum.ansible.com/u/Andrew_Cholakian)\
**Post date:** [May 29, 2014, 5:55pm UTC](https://forum.ansible.com/t/ansible-date-time-variables-not-found/15364/5 "2014-05-29T17:55:08Z")

</div>

Thanks for the quick response Michael! For some reason the whole line I was actually using it in now works. Maybe I had missed a quote or something, but the bracket syntax now works. I don’t know why I didn’t see that in a full hour of staring at it yesterday, but it works now _shrugs_
