Can anyone help me please i get this error on this code

dateEdit1.DateTime == frmMaterialPricing.supplydate

frmmaterialpricing.supplydate this is the declaration on supplydate = (DateTime)txtSupply.text;

When i try to check if datedit1.datetime is equals to supplydate i'm getting error.

Recommended Answers

If you are trying to compare 2 DateTime objects use DateTime.Compare(date1, date2).
Results are:
-1 if date1 < date2
0 if date1 = date2
1 if date1> date2

Jump to Post

== and != are referring to object comparisons. If you want to check wether 2 DateTime values are not equal just do

if (DateTime.Compare(date1, date2) != 0)
{
}
Jump to Post

All 5 Replies

If you are trying to compare 2 DateTime objects use DateTime.Compare(date1, date2).
Results are:
-1 if date1 < date2
0 if date1 = date2
1 if date1> date2

Yes i'm comparing two value

how about != ? is that possible?

== and != are referring to object comparisons. If you want to check wether 2 DateTime values are not equal just do

if (DateTime.Compare(date1, date2) != 0)
{
}

Hi pitic is it possible if date1 is declare likethis DateTime? because i'm accepting null value on it.

Like what? If you're accepting null values you should always do a null check before comparing. And in the example you provided it's not safe to cast the textbox.text as a DateTime unless you have some strict input checking. Rather do a DateTime.ParseExact if you know the date format.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.