I have a column in a database that has a time stamp.I am querying these columns to dump out on a sheet.I'm able to display the dates for the cells that contain an actual timestamp but there are cells that only have "0" in them. So for these cells there is a defualt date of "12-31-1969". All I want is a big fat "0" Please help.the code I have:
while ($row = mysql_fetch_array($sql)) { $username = $row["username"]; $lastvisit = date("n-d-Y",$row["lastvisit"]);$lastactivity = date("n-d-Y",$row["lastactivity"]); $lastpost = date("n-d-Y",$row["lastpost"]);
2/21/2006 5:38:13 PM
I know I could write a "if" statement but I was just wondering if there is an easier way to do this.
2/21/2006 5:41:40 PM
i doubt it. an if statement would add 3-5 lines. just use the if
2/21/2006 6:05:21 PM
rule #324: always make mysql do the work if possible
2/21/2006 6:07:27 PM
use the ternary operator. it gives the functionality of an if/else statement, but in 1 compact line
$lastvisit = ($row["lastvist"] == 0 ? 0 : date("n-d-Y",$row["lastvisit"]));
2/21/2006 6:08:05 PM
DECODE
2/21/2006 6:16:18 PM
DECODE You
2/21/2006 6:27:22 PM
^^^ hmm didnt work but I will read about that to see if its just somethign simple to edit[Edited on February 21, 2006 at 6:29 PM. Reason : ef]
2/21/2006 6:29:28 PM
ok got it:
$lastvisit = ($row["lastvisit"] == 0) ? "No Date" : date("n-d-Y",$row["lastvisit"]);
2/21/2006 6:38:46 PM