Click here to Skip to main content
15,921,028 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I want to check whether a person has applied for leave today for that i am passing DateTime.Now as parameter but i am getting null as result but there records already exists in the table how to check it?
Posted
Updated 31-Jan-12 0:34am
v2

Hi Shashwath,

You need to pass the Parameter value as System.DateTime.Now instead of datetime.now and then in Database you just try the Below Query it will Work,


select Count(*) from Table_Name where Convert(NvarChar(15),LeaveDate,103)=Convert(NvarChar(15),@Parameter_Value,103)
 
Share this answer
 
You are getting the null value because you are not getting a match in the table.
Since,DateTime.Now.ToString() gives the output in the format "dd/MM/yyyy hr:min:sec". Which includes the time(hr:min:sec). So to check the date of the leave. You only need to send the (dd/MM/yyyy) part of today's date.
Which you can achieve by using this code
DateTime dtm = DateTime.Now;
string date = dtm.ToString("dd/MM/yyyy");


Pass this 'date' as parameter.
Next in the database, you would need to check the leave date as

SQL
select CONVERT(VARCHAR(10),leaveDate, 103) as  RequestedDate from Table_Name


It will give you the value in the format(dd/MM/yyyy).


Hope this solves your issue.
Thanks!!
 
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