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.
Asked
Active
Viewed 137 times
0
-
"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 Nov 12 '18 at 17:41
-
Maybe this answer [Inserting datetime into a MS SQL table using pyodbc](https://stackoverflow.com/questions/24458124/inserting-datetime-into-a-ms-sql-table-using-pyodbc) might help! Though in this example they were getting errors. – cosinepenguin Nov 12 '18 at 17:43
-
I will check now for actual value – James Williams Nov 12 '18 at 17:51
-
This is the value coming out of strptime 2018-11-12 18:20:00 – James Williams Nov 12 '18 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 Nov 12 '18 at 18:16
-
Checked to be sure and yes datetime – James Williams Nov 12 '18 at 18:21
1 Answers
0
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.

James Williams
- 1
- 1