How to create a widget in SQL with variables?

zc
New Contributor III

I want to create a widget in SQL and use it in R later. Below is my code


%sql

declare or replace date1 date = "2025-01-31";
declare or replace date2 date ;
set var date2=add_months(date1,5);
 
What's the correct syntax of using date2 to create a widget? I have tried
CREATE WIDGET TEXT date_end  DEFAULT date2;
CREATE WIDGET TEXT date_end  DEFAULT $date2;
CREATE WIDGET TEXT date_end  DEFAULT :date2;
 
and none worked.
 
If there are other ways to let R access a variable in SQL, I'd love to learn that too.
Thank you,