Using datetime.strptime(11/12/18 02:20 PM, '%m/%d/%y %I:%M %p') I enter the date and time into sql server using a stored procedure and I get no errors, all seems fine. But the actual value in the database when checked is 2018-11-12 00:00:00.000. This is the value coming out of strptime 2018-11-12 14:20:00. Why am I not getting the time value? I have checked both the table design and Stored Procedure to make sure that datetime is being used throughout.
-
"No errors" does not necessarily mean "fine." Did you look at the actual value that is getting substituted before you just throw it over the wall at SQL Server?Aaron Bertrand– Aaron Bertrand2018-11-12 17:41:24 +00:00Commented Nov 12, 2018 at 17:41
-
Maybe this answer Inserting datetime into a MS SQL table using pyodbc might help! Though in this example they were getting errors.cosinepenguin– cosinepenguin2018-11-12 17:43:00 +00:00Commented Nov 12, 2018 at 17:43
-
I will check now for actual valueJames Williams– James Williams2018-11-12 17:51:19 +00:00Commented Nov 12, 2018 at 17:51
-
This is the value coming out of strptime 2018-11-12 18:20:00James Williams– James Williams2018-11-12 17:55:26 +00:00Commented Nov 12, 2018 at 17:55
-
Is it possible the column in SQL Server is DATE instead of DATETIME? Seems unlikely if you're getting the 00:00:00.000 at the end, but worth checking.Jeffrey Van Laethem– Jeffrey Van Laethem2018-11-12 18:16:23 +00:00Commented Nov 12, 2018 at 18:16
|
Show 1 more comment
1 Answer
Ok, Figured it out, since I was doing this in 'Ignition' and using a python library, I went into the library file. It was using 'system.db.createSPProcCall' and 'registerInParam' where you must include a value and a type. Since 'system.db.type' does not have a datetime, they had used DATE, wrong! I changed it to use TimeStamp. It worked fine after that. A shout out to @Jeffrey Van Laethem for setting me on the right path.