# How to convert string to int in jinja/macro

**URL:** <https://discourse.getdbt.com/t/how-to-convert-string-to-int-in-jinja-macro/2247>\
**Category:** Archive\
**Created:** [March 11, 2021, 9:19pm UTC](https://discourse.getdbt.com/t/how-to-convert-string-to-int-in-jinja-macro/2247 "2021-03-11T21:19:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![xzheng](https://sea2.discourse-cdn.com/flex020/user_avatar/discourse.getdbt.com/xzheng/32/1694_2.png) [@xzheng](https://discourse.getdbt.com/u/xzheng)\
**Post date:** [March 11, 2021, 9:19pm UTC](https://discourse.getdbt.com/t/how-to-convert-string-to-int-in-jinja-macro/2247/1 "2021-03-11T21:19:31Z")

</div>

tried to use below max\_counter as loop max number. but the result from dbt\_utils.datediff is str. when using lie below will have error: ‘str’ object cannot be interpreted as an integer. but when attempted to convert str to int using {{dbt\_utils.datediff(“‘2018-01-01’”, “‘2018-09-20’”, ‘month’)|int}}  
the result will be 0? anyone know the reason? i just want to have result as number instead of str. why ‘8’ will become 0 after convert.  
anyone can help?

{% macro SP\_WARD\_VILLAGE\_YEARLY\_SALES() %}

{% set max\_counter = dbt\_utils.datediff(“‘2018-01-01’”, “‘2018-09-20’”, ‘month’) %}

create or replace table semantic.test(id int);

{% for counter in range(1,max\_counter ) %}

{% if counter \< max\_counter %}

insert into semantic.test(id)

select {{max\_counter}} ;

{% endif %}

{%set counter = counter+1 %}

{% endfor %}

{% endmacro %}
