Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to compare a input date with the inserted date time in sql server



DateTime dt=Convert.ToDateTime("01-01-1900");
if ((rowLB["CloseDate"] is DBNull) !! (Convert.ToDateTime(rowLB["CloseDate"]==dt)))


this is giving error only increment showing how to compare
Posted
Comments
John C Rayan 31-Jul-15 6:57am    
would you mind explaining to me what the following code does.
if ((rowLB["CloseDate"] is DBNull) !! (Convert.ToDateTime(rowLB["CloseDate"]==dt)))

You're using exclamation marks (!!, ASCII code 33) instead of vertical bars (||, ASCII code 124):
C#
DateTime dt = new DateTime(1900, 1, 1);
if (rowLB.IsNull("CloseDate") || Convert.ToDateTime(rowLB["CloseDate"]) == dt)
{
    ...
}
 
Share this answer
 
Comments
Member 11755579 31-Jul-15 8:44am    
thanx
Instead of using exclamation mark use || operator and Use the Datetime compare methods to get the actual results.
for example, || dt.CompareTo(Convert.ToDateTime(closedate))==0)

If compareTo method returns the values based on,

Less than zero - This instance is earlier than value.

Zero - This instance is the same as value.

Greater than zero - This instance is later than value, or value is null.
 
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