Click here to Skip to main content
15,902,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Get the records when entered value dd matches in dd/mm/yyyy instead of entering dd/mm/yyyy

What I have tried:

select * from tbl_MonthleyIntrest
where tbl_MonthleyIntrest.DateTime = '13';
Posted
Updated 13-Mar-16 22:33pm
Comments
Mehdi Gholam 14-Mar-16 4:28am    
Your question is not clear, explain what you intend to do.
Member 12115746 14-Mar-16 4:30am    
search by only day from dd/mm/yyyy

SELECT [YourDate] FROM [YourTable] WHERE DAY([YourDate])=14
 
Share this answer
 
Try:
SQL
SELECT * FROM tbl_MonthleyIntrest 
WHERE DAY(tbl_MonthleyIntrest.DateTime) = 13

Ignore that - I read it as MySql, not MSSql.
Try:
SQL
SELECT * FROM tbl_MonthleyIntrest 
WHERE DATEPART(dd, tbl_MonthleyIntrest.DateTime) = 13
 
Share this answer
 
v2
Comments
Member 12115746 14-Mar-16 5:07am    
it says Conversion failed when converting date and/or time from character string.
OriginalGriff 14-Mar-16 5:11am    
Simple solution: don't store date values in strings - it always gives problems. Always store values in the most appropriate form: numbers go in INT or FLOAT, dates in DATE or DATETIME. If you don't, then you store up problems for later on, and your data starts to become unusable.
You could bodge round it in this case with SUBSTRING, but it's not recommended - you are just putting a band-aid on a broken leg...
Member 12115746 14-Mar-16 5:16am    
for date time i am using as nvarchar(50)
OriginalGriff 14-Mar-16 5:33am    
I guessed: don't.
It's inefficient in space terms (100 bytes instead of 8), and it creates loads of problems when you want to do something with it: sorting doesn't work, comparisons don't work, culture can't be taken into account, invalid dates are very possible, and so, on, and so on.
Change it now, before you get too much data in there, because the more data you get, the bigger a problem it becomes to fix when you finally decide it just isn't working. If it gets to production? It's a total PITA and can really muck you up...
Member 12115746 14-Mar-16 5:31am    
thank you sir

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