Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
com = new SqlCommand("SELECT MAX(createddate) FROM Payout_Master WHERE sponcorid='" + code + "'", con);
            DateTime date = (DateTime)com.ExecuteScalar();
           

            DateTime datenow = DateTime.Now;
            string frmt = "MM/dd/yyyy";
            string datenow1 = datenow.ToString(frmt);
            if(date!=datenow1)

this shows me this following error

Error:
Operator '!=' cannot be applied to operands of type 'System.DateTime' and 'string'
How should i do to remove this error
Posted
Updated 22-Nov-12 4:26am
v2

Quite simply, you cannot compare two different data types. ie. A string is not comparable with a DateTime.
In order to do this comparison, you'll need to do this:
C#
if( date != DateTime.Now.Date )...
 
Share this answer
 
 
Share this answer
 
Hi

To compare two date their is a DateTime.Compare Method

You can use this method as shown below:

C#
int value= DateTime.Compare(DateTime date1,DateTime date2)


if return value is Zero then both date are same i.e. (date1==date2)

if return value is Less than zero then date1 is is earlier than date2 i.e. (date1<date2)>

if return value is Greater than zero then date1 is later than date2 i.e.(date1>date2)

I hope this will help you....
 
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