# How to execute code depending on julia version

**URL:** <https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029>\
**Category:** General Usage\
**Tags:** versions\
**Created:** [January 22, 2022, 11:23am UTC](https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029 "2022-01-22T11:23:07Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 22, 2022, 2:05pm UTC](https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029/3 "2022-01-22T14:05:12Z")

</div>

> [@bgctw](#):
>
> How can I conditionally execute some code, depending on what julia version it is running on?

```julia
@static if VERSION ≥ v"1.7"
    # do something
end

```

(The reason for the `@static` is so that this check occurs at compile time, which is sometimes important, e.g. if you want to `ccall` a function that doesn’t exist before a certain version then you want to strip it out before compilation.)

> [@Bardo](#):
>
> `Int.([VERSION.major, VERSION.minor])`

You should almost never have to look inside the fields of a [`VersionNumber`](https://docs.julialang.org/en/v1/base/base/#Base.VersionNumber) (`== typeof(VERSION)`) object. Just do comparisons with `v"..."` strings as above. See also the manual on [version number literals](https://docs.julialang.org/en/v1/manual/strings/#man-version-number-literals).

(I noticed that the `VersionNumber` docs don’t talk about comparisons, so I created a PR improving them: [julia#43893](https://github.com/JuliaLang/julia/pull/43893).)

---

_[View the full topic](https://discourse.julialang.org/t/how-to-execute-code-depending-on-julia-version/75029)._
