I have Execute Query activity where I want to pass a variable in as the date. The variable is a string variable containing yesterday’s date (System.DateTime.Today.AddDays(-1).ToString(“yyyy-MM-dd”))
var = yesterdayDate
Here is part of my SQL query below. I want to replace ‘2020-04-07’ with the yesterdayDate variable. The time will remain the same so no need to change that part:
between to_date(‘2020-04-07 12:03:00 PM’ , ‘YYYY-MM-DD HH:MI:SS PM’)
and to_date (‘2020-04-08 12:03:00 PM’ , ‘YYYY-MM-DD HH:MI:SS PM’)
Here is how I tried, but it doesn’t seem to be working:
between to_date(“+”’”+yesterdayDate+”’+ 12:03:00 PM’ , ‘YYYY-MM-DD HH:MI:SS PM’)
and to_date (‘2020-04-09 12:03:00 PM’ , ‘YYYY-MM-DD HH:MI:SS PM’)
Not sure if this is true of youre version of SQL, but in T-SQL, the GETDATE() function returns the current datetime in SQL. So you can get yesterday’s date within the query itself with DATEADD(DAY, -1, GETDATE()) within the query. No need for parameters.
@Anthony_Humphries Thanks. I’ve tried a couple different ways from researching online but I’m getting a date format not recognized error when I run the query.