I have what would seem to be a simple script that collects a date from popup calendar name 'weekSelect', places the value into a variable named weekStart and then formats the variable with dateFormat. What I'm having an issue with is getting the variable to work with the same scripts SQL query. The error I receive, GatewayException & SQLServerException: Conversion failed when converting date and/or time from character string.
Code (simplified as to not show all tables):
import datetime
reportDate = datetime.datetime.now().strftime("%Y-%m-%d") # Convert to string format
weekStart = event.source.parent.getComponent('weekSelect').date
weekEnd = system.date.addDays(weekStart, 7)
####### Convert weekStart and weekEnd to SQL-compatible format
weekStart = system.db.dateFormat(weekStart, "yyyy-MM-dd")
weekEnd = system.db.dateFormat(weekEnd, "yyyy-MM-dd")
query = """
DECLARE @weekStart DATE = 'weekStart';
DECLARE @weekEnd DATE = 'weekEnd';
SELECT
*
FROM
timesheets t
JOIN projects p ON t.projectId = p.id
JOIN users u ON t.userID = u.id
WHERE
t.startTime >= @weekStart AND t.startTime < @weekEnd
ORDER BY
t.startTime
"""
result = system.db.runQuery(query).
Seems I'm having an issue getting the variable called from the query. Several attempts in different formats have failed.