简体   繁体   中英

Date passed as argument to SQL Server Stored Procedure - called from pyodbc script

Is there something that happens to the date formatting when passing a date as an argument to a SQL server stored procedure?

I have a python script that is on Windows Server 2012 that calls a stored procedure using pyodbc.

This works without a problem for some dates (eg '2020-01-30') but not for other dates (eg '2020-01-31'). If the stored procedure is called from SQL Server Management Studio with one of the dates that DOES NOT work from the Python script (eg '2020-01-31') it works without a problem.

What datatype is the parameter? The DATETIME datatype is known to be rather picky about what string literals it can properly interpret as valid dates.

The general consensus is that you should either use other datatypes (eg DATE , if you only need the date - no time portion) - or if that's not feasible, then use the ISO-8601 formatting for the date:

20200131
YYYYMMDD

without any dashes or anything.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM