Convert date to DateTime in SQL and Query other than

I am having a problem with the simplest command in SQL Server Management. The problem seems to be related to the conversion process. The current column is only set to date, but I need to specify a range by date and time. Ultimately I would like to query where the date and time is greater than the previous datetime days.

Can anyone help me? I am pulling hair for the simplest query.

Select
  FROM [CustomerTracking].[dbo].[Submission]
  WHERE 
  Date(CONVERT(Datetime, '0000-00-00 00:00:00', 102)) 
  is BETWEEN '2012-03-14 12:23:00' AND 'Now'
GO

      

+3


source to share


2 answers


SELECT * FROM [Submission]
WHERE CONVERT(DATETIME,[DateOnlyColName]) 
    BETWEEN CONVERT(DATETIME,'01/01/2012 12:15:00') AND GETDATE()

      



+4


source


You probably want something like this:



Select *
From [CustomerTracking].[dbo].[Submission] 
Where Convert(Datetime, [YOUR_DATE_COLUMN], 102) Between '2012-03-14 12:23:00'
AND Getdate()

      

+1


source







All Articles