Link to home
Start Free TrialLog in
Avatar of johnkainn
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?
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

You where clause should be:

where left(convert(nvarchar(8), myDateTimeField, 108), 2) = '14'
Don't know if it's exactly the best, but it should work:

SELECT datetime FROM yourtablename WHERE datetime LIKE '%14:10%'
ASKER CERTIFIED SOLUTION
Avatar of Lee
Lee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You really should use DATEPART function to do it right.
http://msdn.microsoft.com/en-us/library/ms174420.aspx
For example
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
Obviously substitute 'ABook' for your table name and 'DateReceived' for your column name in the example above.