I need to compare between dates by converting the SQL Server datetime
value (ex: 20-Feb-14 12:52:48 PM
) to yyyyMMddhhmmss
I tried the following but still need to replace the spaces and ":" and can't do multiple replace
REPLACE(RIGHT(CONVERT(VARCHAR(19), (OrderDate), 120), 19), '-', '')
Any ideas?
Here is my full code:
Dim dsOrders As New DataSet
Dim daOrders As SqlDataAdapter
Dim Cnn As New SqlClient.SqlConnection(System.Configuration.ConfigurationManager.AppSettings("ConnectionString"))
Dim strSQL As String
strSQL = "Select O.OrderID,O.Status,O.OrderDate, O.DeliveryDate, OD.Title,OD.Data from SPLBL_Orders O join SPLBL_OrderData OD on O.OrderID=OD.OrderID where OD.LanguageID=1"
'''' Generate Filter Results
If txtKeyword.Text.ToString <> "" Then
strSQL = strSQL + " OR OD.Data Like N'%" + txtKeyword.Text.ToString + "%'"
End If
If txtMemberID.Text.ToString <> "" Then
strSQL = strSQL + " and O.MemberID = " + txtMemberID.Text.ToString
End If
If chkFeatured.Checked Then
strSQL = strSQL + " and O.Featured=1"
End If
Dim lstStatus As ListItem
Dim strStatus As String = ""
For Each lstStatus In ddlStatus.Items
If lstStatus.Selected Then
If strStatus <> "" Then
strStatus = strStatus + ","
End If
strStatus += lstStatus.Value.ToString()
End If
Next
If strStatus <> "" Then
strSQL = strSQL + " and O.Status IN(" + strStatus + ")"
End If
If txtStartDate.Text <> "" Then
Dim strSdate As DateTime = txtStartDate.Text.ToString
Dim strStart = strSdate.ToString("yyyyMMddhhmmss")
If txtEndDate.Text <> "" Then
Dim strEdate As DateTime = txtEndDate.Text.ToString
Dim strEnd As String
If txtEndDate.Text <> "" Then
strEnd = strEdate.ToString("yyyyMMddhhmmss")
Else
strEnd = Date.Today.ToString("yyyyMMddhhmmss")
End If
strSQL = strSQL + " and REPLACE(REPLACE(REPLACE((CONVERT(VARCHAR(19), (OrderDate), 120)), ':', ''), '-', ''), ' ', '') Between " + strStart + " and " + strEnd + ""
End If
End If
strSQL = strSQL + " order by OD.OrderID desc"