In a while
loop how can I have a date displayed only if that date exists?
E.g.: If date is 0000-00-00
, display nothing.
I am currently reading the date as follows, but I am getting 01-01-1970
when 0000-00-00
:
date('d-m-Y', strtotime($row['date']))
The is_null() function checks whether a variable is NULL or not. This function returns true (1) if the variable is NULL, otherwise it returns false/nothing.
Hi Elhaddad, you can directly check if Datetime field is empty using == null condition as shown in example below.
$('form input[name="birthDate"])'). blur(function () { var dob = $("#dob"). val(); if(dob == "") { $("#dobAlert").
If you are using DateTime then DateTime dat = new DateTime();if (dat==DateTime. MinValue){//unassigned datetime}Or if you are using nullable DateTime then DateTime? dat = null;if (!
You should check first what is there in date field whether it contains date or its NULL. According to result you can read date .
while ($row = mysql_fetch_array($result)) {
if (strtotime($row['date']) != '0000-00-00') {
mydate = date('d-m-Y', strtotime($row['date']));
} else {
mydate = '';
}
}
try this, its work for me
while($row = mysql_fetch_array($result)){
if(strtotime($row['date']) > 0){
echo date('d-m-Y', strtotime($row['date']));
}else{
echo 'Date not valid or null';
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With