OS=Win10Pro, Python=3.7
SQL Server=2014(12.0.4237.0), pyodbc=4.0.27, ODBCドライバ=SQL Server(10.00.18362.01)
にて単純なテーブルを作成して試してみましたが、正常に動作しました。
参考まで。
Python
1import pyodbc
2
3cnxn = pyodbc.connect(r'Driver={SQL Server}; Server=.\SQLEXPRESS; Database=dbTest; Trusted_Connection=yes;')
4cursor = cnxn.cursor()
5cursor.execute('SELECT * FROM t_test WHERE DATEPART ( HOUR , 登録時刻) > 12;')
6row = cursor.fetchall()
7print(row) # [(4, datetime.datetime(2020, 2, 6, 13, 0)), (5, datetime.datetime(2020, 2, 7, 14, 0))]
テーブル情報
SQL
1USE [dbTest]
2GO
3SET ANSI_NULLS ON
4GO
5SET QUOTED_IDENTIFIER ON
6GO
7CREATE TABLE [dbo].[t_test](
8 [id] [bigint] NOT NULL,
9 [登録時刻] [datetime] NULL,
10 CONSTRAINT [PK_t_test] PRIMARY KEY CLUSTERED
11(
12 [id] ASC
13)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
14) ON [PRIMARY]
15GO
16INSERT [dbo].[t_test] ([id], [登録時刻]) VALUES (1, CAST(N'2020-02-03T10:00:00.000' AS DateTime))
17GO
18INSERT [dbo].[t_test] ([id], [登録時刻]) VALUES (2, CAST(N'2020-02-04T11:00:00.000' AS DateTime))
19GO
20INSERT [dbo].[t_test] ([id], [登録時刻]) VALUES (3, CAST(N'2020-02-05T12:00:00.000' AS DateTime))
21GO
22INSERT [dbo].[t_test] ([id], [登録時刻]) VALUES (4, CAST(N'2020-02-06T13:00:00.000' AS DateTime))
23GO
24INSERT [dbo].[t_test] ([id], [登録時刻]) VALUES (5, CAST(N'2020-02-07T14:00:00.000' AS DateTime))
25GO