Hi @Don75 ,
You used a date in a custom format, which can cause errors in the query. You can use the DateTime.ParseExact method to parse a custom-formatted date string and then insert it into the query statement.
Dim StartDateStr As String = "May 01"
Dim EndDateStr As String = "Jun 30"
Dim StartDate As DateTime = DateTime.ParseExact(StartDateStr, "MMM dd", CultureInfo.InvariantCulture)
Dim EndDate As DateTime = DateTime.ParseExact(EndDateStr, "MMM dd", CultureInfo.InvariantCulture)
Dim sSql As String = "SELECT [Employee ID], [Date], [Name], [Total Hours], [OT Hours] FROM [Sheet$] WHERE [Employee ID] = '" & EmpID & "' AND Convert(DATE, [Date]) >= '" & StartDate.ToString("yyyy-MM-dd") & "' AND [Date] <= '" & EndDate.ToString("yyyy-MM-dd") & "'"
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.