Check for date

In a loop, whilehow can I show a date only if that date exists?

For example: If the date 0000-00-00, nothing is displayed.

I am currently reading the date as follows, but I get 01-01-1970when 0000-00-00:

date('d-m-Y', strtotime($row['date']))
+3
source share
6 answers

First you need to check what the date field is in, whether it contains the date or its NULL. As a result, you can read the date.

while($row = mysql_fetch_array($result)){ 

if(strtotime($row['date'])!='0000-00-00'){
mydate = date('d-m-Y', strtotime($row['date']));
}else{
mydate ='';
}
}
+2
source

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';
 }
}
+4
source

. strtotime() , .

"0000-00-00" "-0001-11-30". PHP:

dd DD. 0 , - . , "2008-08-00" "2008-07-31" "2008-06-31", "2008-07-01" ( 30 ).

, PHP 5.1.0 0-31, . , , "2008-06-32" .

mm MM 0. 0 . , "2008-00-22" "2007-12-22".

, , : "2008-00-00" "2007-12-00", "2007-11 -30". "0000-00-00" , "-0001-11-30" ( -1 ISO 8601, 2 BC ).

PHP 32- , strtotime ( "0000-00-00" ) false, , , , (30 , -0001) , . 64- PHP , -62169984000 ( ). , 1 1970 30 , -0001.

, strtotime() "0000-00-00" , , , . "0000-00-00" , :

while($row = mysql_fetch_array($result)){
    if($row['date'] != '0000-00-00'){ // string comparison to see if set or not
        echo date('d-m-Y', strtotime($row['date']));
    }
}

, 32- PHP 13 1901 19 2038 . strtotime ($ row ['date']) false, date() 0 "01-01-1970", 0 1 1970 .

+2

foreach($row As $rows){
 if(strtotime($rows['date']) == ''){
    echo "N/A";
  }else{
echo date('d-m-Y', strtotime($rows['date']));
 }
echo "<br/>";

}

strtotime of "0000-00-00" AND "" is equal to "".

+1

What you can do is replace all the values of 0, -, :and of the date string, or date and time, to check whether it is empty.

if (empty(str_replace(array("0", "-", ":", " "), "", $mydate)))
{
  echo "empty date";
}
else
{
  echo "not empty date";
}
+1
source

An easy way to do this is to evaluate $ row ['date'] as an integer and check the value, for example:

if(!empty((int)$row['date']))
{
  echo "NOT empty";
}
else echo "EMPTY";

OR short version:

!empty((int)$row['date']) ? echo "NOT empty" : echo "EMPTY";
+1
source

All Articles