johnkainn
asked on
hour:min from datetime
Hi,
I would like to select all from a DateTime column where hour is 14 and minutes 10, i.e. 14:10.
It does not matter which date it is. How is best to do this?
I would like to select all from a DateTime column where hour is 14 and minutes 10, i.e. 14:10.
It does not matter which date it is. How is best to do this?
Don't know if it's exactly the best, but it should work:
SELECT datetime FROM yourtablename WHERE datetime LIKE '%14:10%'
SELECT datetime FROM yourtablename WHERE datetime LIKE '%14:10%'
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You really should use DATEPART function to do it right.
http://msdn.microsoft.com/en-us/library/ms174420.aspx
http://msdn.microsoft.com/en-us/library/ms174420.aspx
For example
select * from <tablename> where DATEPART(minute, columnname) = 12
select * from <tablename> where DATEPART(minute, columnname) = 12
Or for your example
select * from ABook where DATEPART(hour, DateReceived) = 14 AND DATEPART(minute, DateReceived) = 10
select * from ABook where DATEPART(hour, DateReceived) = 14 AND DATEPART(minute, DateReceived) = 10
Obviously substitute 'ABook' for your table name and 'DateReceived' for your column name in the example above.
where left(convert(nvarchar(8), myDateTimeField, 108), 2) = '14'