I have a value comming from database which is a date in informix.Sometimes this value will be null or else it will be a date.I am comparing that value with todays date like the following.
if(value_from_db <= todays_date){
//display Todays greater
}
else{
//Display Todays smaller
}
What will be the output here.It will print Todays greater
or Todays smaller
My question is that if value_from_db is NULL
will it goes inside the if condition or inside the else condition.I found something in this which is described as
A date field gets NULL value. If I use a FOR EACH even less or greather than a user date this NULL field record appear. It seems to be NULL greather than all other dates and at same time lees than all other dates.
If the field which stores NULL value is an index component NULL values are sorted high.
I need to convert this into php but after analysing the correct o/p.In case of php
if(strtotime(NULL) <= time())
echo 'Todays greater';
else
echo 'Today is smaller';
This will ouput
Todays greater
I am confused.Any help is much appreciated.
It will enter ELSE
either you do <= todays_date
or >= todays_date
, since NULL
is neither bigger or smaller.
You should have something on the query that fuels that value_from_db to not return you NULL values OR validate specifically for them in the IF.
Here's a procedure to test that:
CREATE TABLE datet(date1 DATE);
INSERT INTO datet VALUES(null);
CREATE PROCEDURE validateNullDate()
RETURNING char(5)
DEFINE dateVar DATE;
SELECT date1 INTO dateVar FROM datet;
IF dateVar <= TODAY THEN
RETURN "if";
ELSE
RETURN "else";
END IF
END PROCEDURE;
Even changing the IF to: IF dateVar >= TODAY THEN
. You'll always get "else".
EDIT:
About your question of getting strtotime(NULL)
smaller than today, you can find a good explanation on this answer:
NULL is interpreted as 0 by strtotime, since it want to be passed an integer timestamp. A timestamp of 0 means 1-1-1970.
So it will go in the if.