Fala, guys! Tenho as datas com dois tipos de formatos diferentes no banco de dados, exemplo:
- MM/dd/yyyy
- dd/MM/yyyy HH:mm:ss
Mas na hora de fazer na consulta no VB.NET, fiz assim e não funciona.
Public Function teste (ByVal dtpInicio As String, ByVal dtpFim As String) As List(Of Teste)
'Consulta com a data dd/MM
Dim retorno As New List(Of Teste)
Try
Conectar()
cmd.CommandText = "SELECT * FROM NOME_TABELA WHERE NOME_COLUNA BETWEEN '" &
dtpInicio.ToString("dd/MM/yyyy HH:mm:ss") & "' AND '" & dtpFim.ToString("dd/MM/yyyy HH:mm:ss") & "' ORDER BY NOME_COLUNA"
dr = cmd.ExecuteReader
While dr.Read
retorno.Add(New Teste With {
.NOME_COLUNA = dr(0)
})
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Desconectar()
End Try
'Consulta com a data dd/MM
Dim retorno As New List(Of Teste)
Try
Conectar()
cmd.CommandText = "SELECT * FROM NOME_TABELA WHERE NOME_COLUNA BETWEEN '" &
dtpInicio.ToString("MM/dd/yyyy") & "' AND '" & dtpFim.ToString("MM/dd/yyyy") & "' ORDER BY NOME_COLUNA"
dr = cmd.ExecuteReader
While dr.Read
retorno.Add(New Teste With {
.NOME_COLUNA = dr(0)
})
End While
Catch ex As Exception
MsgBox(ex.Message)
Finally
Desconectar()
End Try
Return retorno
End Function
Alguma dica, galera?
ToString("yyyyMMdd")