Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Date to DateTime in SQL and Query great than

Tags:

date

sql

datetime

I am having an issue with the most simple command in SQL Server Management. It seems the issue with is in the converting process. The current column is set to date only but I need to be able to specify the range under date and time. I would ultimately like to query where datetime is greater than the previous days datetime.

Can anyone lend me a hand on this one? I am pulling may hair out on the most simple 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
like image 635
Wishn4fishn Avatar asked Mar 15 '12 13:03

Wishn4fishn


2 Answers

SELECT * FROM [Submission]
WHERE CONVERT(DATETIME,[DateOnlyColName]) 
    BETWEEN CONVERT(DATETIME,'01/01/2012 12:15:00') AND GETDATE()
like image 192
Kaf Avatar answered Oct 23 '22 00:10

Kaf


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()
like image 3
codingbadger Avatar answered Oct 23 '22 00:10

codingbadger