How to query select with two different date formats in VB.NET?

1

Talk, guys! I have the dates with two different types of formats in the database, for example:

  • MM / dd / yyyy
  • dd / MM / yyyy HH: mm: ss

But at the time of the VB.NET query, I did so and it does not work.

    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

Any tips, guys?

    
asked by anonymous 24.04.2018 / 16:34

0 answers