# Timestamp() template function

**URL:** <https://discuss.hashicorp.com/t/timestamp-template-function/23341>\
**Category:** Packer\
**Created:** [April 19, 2021, 12:09pm UTC](https://discuss.hashicorp.com/t/timestamp-template-function/23341 "2021-04-19T12:09:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pfuntner](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pfuntner/32/3927_2.png) [@pfuntner](https://discuss.hashicorp.com/u/pfuntner)\
**Post date:** [April 19, 2021, 12:09pm UTC](https://discuss.hashicorp.com/t/timestamp-template-function/23341/1 "2021-04-19T12:09:40Z")

</div>

I’m looking at converting some packer JSON configuration files to HCL2. I have been playing with the `packer hcl2_upgrade` command with release 1.7.2 and have had success building an image with a new configuration file.

packer is recommending that a string like `"{{isotime \"2006-01-02\"}}"` be changed to make use of the timestamp and formatdate functions. I found the example on the [timestamp page](https://www.packer.io/docs/templates/hcl_templates/functions/datetime/timestamp) but it doesn’t seem to work for me the same way:

```
$ packer console
> timestamp() # this is the statement I entered
> timestamp() # this is the response
> "{{timestamp()}}"
???????: Interpolation error

template: root:1: unexpected "(" in operand

> "{{timestamp}}"
> "1618833849"
> exit
$

```

I’m not even sure if I should be using `packer console` to play with expressions like this. Am I doing something wrong?

---

<div class="post-metadata">

**Author:** ![pfuntner](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/pfuntner/32/3927_2.png) [@pfuntner](https://discuss.hashicorp.com/u/pfuntner)\
**Post date:** [April 19, 2021, 12:14pm UTC](https://discuss.hashicorp.com/t/timestamp-template-function/23341/2 "2021-04-19T12:14:54Z")

</div>

Oh!!! It looks like `packer console` does not use work in hcl2 by default!

```
$ packer console --config-type=hcl2
> timestamp()
> 2021-04-19T12:13:52Z
```

---

<div class="post-metadata">

**Author:** ![sylviamoss](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sylviamoss/32/7064_2.png) [@sylviamoss](https://discuss.hashicorp.com/u/sylviamoss)\
**Post date:** [April 19, 2021, 12:16pm UTC](https://discuss.hashicorp.com/t/timestamp-template-function/23341/3 "2021-04-19T12:16:53Z")

</div>

Hey there,  
To run HCL2 functions in the packer console you need to specify that when starting the console, like :

```auto
$ packer console --config-type=hcl2

```

Anyways, another option to what you’re looking for is the `legacy_isotime` function. You can use like:

```auto
$ packer console --config-type=hcl2
> legacy_isotime("2006-01-02")         
> 2021-04-19 # output

```

---

<div class="post-metadata">

**Author:** ![sylviamoss](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sylviamoss/32/7064_2.png) [@sylviamoss](https://discuss.hashicorp.com/u/sylviamoss)\
**Post date:** [April 19, 2021, 12:17pm UTC](https://discuss.hashicorp.com/t/timestamp-template-function/23341/4 "2021-04-19T12:17:37Z")

</div>

You figured out by yourself while I was replying. 😆
