Link to home
Start Free TrialLog in
Avatar of danielolorenz
danielolorenz

asked on

Getting an Error When Comparing Date to Null?

I am getting an error when comparing date to null.  Otherwise datetime works fine.

Examples:

if (MyDate == null)
  x = 1;

Thanks,

Dan
Avatar of danielolorenz
danielolorenz

ASKER

The error I get is string is not instantiated.  However when the variable if populated with a real datetime, the code works fine.
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the type of MyDate?
It is of type DateTime.  Can you send me an example of how to correctly write this check?

Thanks,

Dan
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That isn't the problem.  The problem is that you can not do the comparison.  You can not check to see if something equals null.  You can only check to see if it is Not null.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Then I don't understand the difference.  And I found out that PHP has 'NULL' as a defined value meaning no value so you can check for it.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial