Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if date is empty

Tags:

html

php

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']))
like image 641
user1347219 Avatar asked May 05 '12 12:05

user1347219


People also ask

How do you check if the date is empty in PHP?

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.

How do I check if a date field is empty in Python?

Hi Elhaddad, you can directly check if Datetime field is empty using == null condition as shown in example below.

How check date is null in jquery?

$('form input[name="birthDate"])'). blur(function () { var dob = $("#dob"). val(); if(dob == "") { $("#dobAlert").

How do I check if a nullable DateTime is null?

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 (!


2 Answers

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 = '';
    }
}
like image 155
Dhruvisha Avatar answered Sep 29 '22 05:09

Dhruvisha


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';
 }
}
like image 35
Tushar Gohel Avatar answered Sep 29 '22 04:09

Tushar Gohel