0

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.

2
Contributors
5
Replies
15
Views
4 Years
Discussion Span
Last Post by pitic
0

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

0

== 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)
{
}
0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.