HelderPinto79


Hi...

I'm with a problem here... I need to convert a date in a string like dd-mm-yyyy to yyyy-mm-dd in a SQL Query... How can i do that

I need to use that in a query like this :

Select CodeID, Name From Exams Where ExDate Between @Date1 And @Date2

This is urgent... someone help me please





Re: Help me convert date.. Urgent please

Waldrop


If the "ExDate" in your "Exams" table is a dateTime field I don't understand why the code you've given won't work. Is "ExDate" datetime or some other datatype




Re: Help me convert date.. Urgent please

HelderPinto79

Dim strCN As String = My.Settings.InovaConnectionString

Dim cn As New SqlClient.SqlConnection(strCN)

'Creates DataAdapter

Dim DataAdapt As New SqlClient.SqlDataAdapter("SELECT dbo.ORDEM_PROD_CB.Codigo, dbo.ORDEM_PROD_LN.CBarras, dbo.ORDEM_PROD_LN.Cod_Prod, dbo.ORDEM_PROD_LN.Largura, dbo.ORDEM_PROD_LN.Altura, dbo.ORDEM_PROD_LN.Quantidade, dbo.ORDEM_PROD_CB.Data_Entrega FROM dbo.ORDEM_PROD_CB INNER JOIN dbo.ORDEM_PROD_LN ON dbo.ORDEM_PROD_CB.Codigo_Auto = dbo.ORDEM_PROD_LN.Codigo WHERE (dbo.ORDEM_PROD_LN.Pronto = 0) AND (dbo.ORDEM_PROD_LN.Cod_Prod IN (" & Filtra_Optm_mnu2.VidroSelec.ToString & ")) AND (dbo.ORDEM_PROD_CB.Data_Entrega BETWEEN '" & Filtra_Optimizacao.Data_Entrega.ToString + "' AND '" & Filtra_Optimizacao.Data_Entrega_F.ToString + "')", cn)

Dim ds As New DataSet

DataAdapt.Fill(ds, "ORDEM_PROD_LN")

Me.ORDEM_PROD_LNDataGridView.DataSource = ds.Tables("ORDEM_PROD_LN")

 

This is my code... I'm creating a sql command... the dates in the string are like DD-MM-YYYY but in the database they are stored like YYYY-MM-DD... So when i'm comparing this give me an error...

 I tried this... but it doesnt work...

 SELECT dbo.ORDEM_PROD_CB.Codigo, dbo.ORDEM_PROD_LN.CBarras, dbo.ORDEM_PROD_LN.Cod_Prod, dbo.ORDEM_PROD_LN.Largura, dbo.ORDEM_PROD_LN.Altura, dbo.ORDEM_PROD_LN.Quantidade, dbo.ORDEM_PROD_CB.Data_Entrega
FROM dbo.ORDEM_PROD_CB INNER JOIN dbo.ORDEM_PROD_LN ON dbo.ORDEM_PROD_CB.Codigo_Auto = dbo.ORDEM_PROD_LN.Codigo
WHERE (dbo.ORDEM_PROD_LN.Pronto = 0)
AND (dbo.ORDEM_PROD_CB.Data_Entrega BETWEEN CONVERT (smalldatetime,'26-12-2006', 110) AND CONVERT (smalldatetime,'27-12-2006', 110))







Re: Help me convert date.. Urgent please

Waldrop

I would suggest this instead:

CONVERT (smalldatetime,'26-12-2006', 105)





Re: Help me convert date.. Urgent please

HelderPinto79

thanks man!!! You save my life!!

It works!






Re: Help me convert date.. Urgent please

Waldrop

You're welcome! :-)