Link to home
Start Free TrialLog in
Avatar of peter-cooper
peter-cooper

asked on

if statement not displaying my statement

I am trying to change what is displayed by using an if statement to change the value.

 After I have queried database, instead of having '00-00-0000' in the date field if there is no date set, i would change it to 'No date set'. However, this is not updating the display with that text. Can someone point out where I have gone wrong in my code. Thanks

$query_rs_rpt_in = sprintf("SELECT * FROM boxes WHERE customer = '%s'AND COALESCE(custref,'') != ''", $colname_rs_rpt_in);

Open in new window


<?php 	

      if ($row_rs_rpt_in['boxin_date'] == '00-00-0000')
		     
             {echo 'No date set';}
      else 
             {echo KT_formatDate($row_rs_rpt_in['boxin_date']);} 

?>

Open in new window

Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Avatar of peter-cooper
peter-cooper

ASKER

Sorry Ray, do not understand your answer. Thanks
Read the article.  There is a standard for date formats in computing.  ISO-8601 makes life easier because it creates predictable formats for date/time strings.

Executive summary:

1. Define your table columns with data type = DATE or DATETIME
2. Make the default value '0000-00-00 00:00:00'
3. Convert all date representations to ISO-8601 with the date('c') formatter.
4. Magically, your date computations will start to work sensibly!
Avatar of Chris Stanyon
var_dump the data and you'll see instantly whether it should match:

var_dump($row_rs_rpt_in['boxin_date']);
if ($row_rs_rpt_in['boxin_date'] == '00-00-0000') {
   echo 'No date set';
} else {
   echo KT_formatDate($row_rs_rpt_in['boxin_date']);
} 

Open in new window

If your database is not returning EXACTLY 00-00-0000 then your IF won't match - it's unlikely as dates are usually stored as YYYY-MM-DD, so it's probably 0000-00-00!
@Chris

It shows as this: string '0000-00-00' (length=10) so I have changed but I also think I need to change and check for and NULL entries. How would I check for NULL Chris.
@Ray Thank you
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Edit...

2. Make the default value '0000-00-00 00:00:00' for DATETIME columns
2.A. Make the default value '0000-00-00' for DATE columns
2.B. Make both types NOT NULL
Considering this and your other question about how to handle dates in data bases, you might want to read this brief but thoughtful article from another of our colleagues here at EE.
https://www.experts-exchange.com/Programming/Languages/SQL_Syntax/A_11210-Beware-of-Between.html
Thanks once again Chris.
NP.  I think you can change the contents of the solution :-)