# Accessing environment variable from jinja code/macro

**URL:** <https://discourse.getdbt.com/t/accessing-environment-variable-from-jinja-code-macro/13065>\
**Category:** Help\
**Tags:** jinja\
**Created:** [April 25, 2024, 5:49am UTC](https://discourse.getdbt.com/t/accessing-environment-variable-from-jinja-code-macro/13065 "2024-04-25T05:49:58Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seeraj](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Seeraj](https://discourse.getdbt.com/u/Seeraj)\
**Post date:** [April 25, 2024, 5:49am UTC](https://discourse.getdbt.com/t/accessing-environment-variable-from-jinja-code-macro/13065/1 "2024-04-25T05:49:58Z")

</div>

## The problem I’m having is the environment variable which set in the dbt Cloud UI is not accessible in jinja set -{% set flag = env\_var(‘dbt\_FLAG’) %}

## I wanted to access the environment variable value based on which I’m generating a value for the date.

Kindly help on this

## Some example code or error messages

```auto
{% macro get_date() %}
{% set flag = env_var('DBT_FLAG') %}
{% if modules.datetime.date.today().day in (8,9,10,11,12,13) or flag == 1 %}
{% set var_date = modules.datetime.date.today() - modules.datetime.timedelta(days=modules.datetime.date.today().day) %}
{% else %}
{% set var_date = modules.datetime.date.today() %}
{% endif %}
{{ return(var_date) }}
 {% endmacro %}

```

---

<div class="post-metadata">

**Author:** ![Seeraj](https://avatars.discourse-cdn.com/v4/letter/s/f6c823/32.png) [@Seeraj](https://discourse.getdbt.com/u/Seeraj)\
**Post date:** [April 26, 2024, 5:49am UTC](https://discourse.getdbt.com/t/accessing-environment-variable-from-jinja-code-macro/13065/2 "2024-04-26T05:49:14Z")

</div>

Variable is accessible through the macro without any issue. Checked in compiled code.
