# Automatically update a constant on every build

**URL:** <https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474>\
**Category:** Help & Support\
**Created:** [December 11, 2019, 3:20pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474 "2019-12-11T15:20:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudo-nice](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/sudo-nice/32/230_2.png) [@sudo-nice](https://forum.crystal-lang.org/u/sudo-nice)\
**Post date:** [December 11, 2019, 3:20pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474/1 "2019-12-11T15:20:30Z")

</div>

Hello!

I wonder, what would be a simple way to update a constant on every build? My intuitive approach was like the following, but that wouldn’t work.

```crystal
{{ VERSION = Time.utc }}
puts VERSION

```

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [December 11, 2019, 3:34pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474/2 "2019-12-11T15:34:43Z")

</div>

I’m pretty sure you can just do `TIME = Time.utc`. See the second codeblock in [https://crystal-lang.org/reference/syntax\_and\_semantics/constants.html](https://crystal-lang.org/reference/syntax_and_semantics/constants.html).

---

<div class="post-metadata">

**Author:** ![sudo-nice](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/sudo-nice/32/230_2.png) [@sudo-nice](https://forum.crystal-lang.org/u/sudo-nice)\
**Post date:** [December 11, 2019, 3:53pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474/3 "2019-12-11T15:53:55Z")

</div>

Thank you, but if I just do `TIME = Time.utc`, the constant will update on every _run_, rather than on every _build_, right? I might be missing something here, though.

---

<div class="post-metadata">

**Author:** ![Blacksmoke16](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/blacksmoke16/32/1241_2.png) [@Blacksmoke16](https://forum.crystal-lang.org/u/Blacksmoke16)\
**Post date:** [December 11, 2019, 4:02pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474/4 "2019-12-11T16:02:52Z")

</div>

Ah, in that case you could use [https://crystal-lang.org/api/master/Crystal/Macros.html#`(command):MacroId-instance-method](https://crystal-lang.org/api/master/Crystal/Macros.html#%60(command):MacroId-instance-method) to do like

```auto
TIME = {{ `date`.stringify }}

```

Of course this would require that the system that builds the binary has a `date` command.

What’s the use case of this? Wouldn’t it be better to follow semver and just manually update the version when a release changes something?

---

<div class="post-metadata">

**Author:** ![sudo-nice](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.crystal-lang.org/sudo-nice/32/230_2.png) [@sudo-nice](https://forum.crystal-lang.org/u/sudo-nice)\
**Post date:** [December 11, 2019, 4:23pm UTC](https://forum.crystal-lang.org/t/automatically-update-a-constant-on-every-build/1474/5 "2019-12-11T16:23:19Z")

</div>

It works, thanks!  
That’s for a really small utility, and I always forget to bump the version.
