Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!
How to use LIKE statement on a column of DateTime in MS SQL Server? I tried this code:

SQL
SELECT     custid, datetoday
FROM         customers
WHERE     (CONVERT(VARCHAR, datetoday, 101) LIKE '5/13/2014%')

but it gives me nothing :(

my dattetime column stores data like this: 5/13/2014 12:00:00 AM

Help please!
Posted
Comments
DamithSL 13-May-14 2:33am    
you want to select records for today date?
charliedev 13-May-14 2:38am    
Yes, I want to see the records for today only.
DamithSL 13-May-14 2:41am    
check my answer below
Bernhard Hiller 13-May-14 2:40am    
Is it necessary that you store the value as a DateTime instead of Date only? See http://technet.microsoft.com/en-us/library/bb630352%28v=sql.100%29.aspx

Quote:
I want to see the records for today only.

then try below
SQL
SELECT custid, datetoday
FROM customers
where  Cast(DATEDIFF(dd, datetoday, getDate()) as int) =0
 
Share this answer
 
Comments
charliedev 13-May-14 2:45am    
This is perfect! Thanks so much :)
DamithSL 13-May-14 2:51am    
You are welcome!
charliedev 13-May-14 3:10am    
follow up question, what is the "dd" for in this line:
where Cast(DATEDIFF(dd, datetoday, getDate()) as int) =0
DamithSL 13-May-14 3:30am    
check http://technet.microsoft.com/en-us/library/ms189794.aspx
dd for day
Depending on your objective, check these out:
1. sql-server-datetime-like-select[^]
2. sql-like-statement-on-a-datetime-type[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900