-
Compare two Dates.
hi guyz! Currently, i have the code below
Code:
if (dtpDate.Value.ToShortDateString != DateTime.Now.ToShortDateString)
{
result = MessageBox.Show(this,"The date is not the date today.", "BCMD", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
MessageBox.Show(this, result.ToString ());
}
but when try to run it it gives me an error saying "Operator '!=' cannot be applied to operands of type 'method group' and 'method group'". Can anybody please tell me what is the right way to compare two dates? thanks in advance!!!
-
Re: Compare two Dates.
Why not just use DateTime.Compare() method to compare the dates?
-
Re: Compare two Dates.
add () after ToShortDateString if you are using c#.
-
Re: Compare two Dates.
Yes, because what you're doing currently is comparing object methods. You need to add the argument list parentheses () to actually call the method and use its return value.
Note that you don't need to call that method at all, if all you want to do is compare the date values.
-
Re: Compare two Dates.
-
Re: Compare two Dates.
-
Re: Compare two Dates.
Unless you have any further questions please go to the "Thread Tools" menu above the first post and click "Mark Thread Resolved". This will let other forum users know your question has been answered. Thanks!