user377419
user377419

Reputation: 4999

PHP/MySql - DateTime detecting if values was assigned?

I want to make an if statement that only runs if the datetime value is NOT null (0000-00-00 00:00:00)

I have passed the value via a query into a variable but how do i determine if it equals 0000-00-00 00:00:00?

$query = "SELECT * FROM stats WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "' "; 
$result = mysql_query($query);

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
{
  $money = $row['money'];
  $bank_money = $row['bank_money'];
  $ap = $row['ap'];
  $exp = $row['exp']; 
  $last_ap_update = $row['last_ap_update'];
} 

if ($last_ap_update != ){ //Can i verify its NULL-ness here so i can run this if stament or run else?
}

Upvotes: 3

Views: 1417

Answers (5)

2ndkauboy
2ndkauboy

Reputation: 9377

Why not adding the comparison to your sql statement?

$query = "SELECT * FROM stats WHERE member_id='" . $_SESSION['SESS_MEMBER_ID'] . "' AND  last_ap_update > 0";

Yes, you can use > 0 but you can also use <> '0000-00-00 00:00:00' if you prefer that.

Upvotes: 0

fredley
fredley

Reputation: 33901

$last_ap_update != strtotime("0000-00-00 00:00:00")

Upvotes: 0

Dan Hanly
Dan Hanly

Reputation: 7839

if ($last_ap_update != "0000-00-00 00:00:00"){
    [process]
}

Upvotes: 1

Christophe
Christophe

Reputation: 4828

You store it into a variable so you can use it as a string

if ($last_ap_update != "0000-00-00 00:00:00"){
}

Upvotes: 1

shamittomar
shamittomar

Reputation: 46692

Why not directly compare it :

if ($last_ap_update != "0000-00-00 00:00:00")
{
      //do whatever.
}

Upvotes: 5

Related Questions