Reputation: 2477
When a use make a get form my website for a date that is not yet available in the database he get something like 1, Jan 1970.
<?php echo date("D j, M Y", strtotime($row["DATE"])); ?>
how to give " not yet available instead of the 1,jan 1970
Upvotes: 0
Views: 94
Reputation: 4270
strtotime
returns FALSE or -1 (depends on which version of PHP you're running). Just check for this case.
$date = strtotime($ROW['DATE']);
// need to change this next line depending on PHP version!
if ($date === false || $date == -1) {
print "Not yet available";
} else {
print date("D j, M Y", $date);
}
Upvotes: 0
Reputation: 4250
The value returned by mysql depends on column datatype if you have datetime or timestamp the value returned would be 0000-00-00 00:00:00 and if you have date then value would be 0000-00-00. Try using this
if ($row["DATE"] != '' || $row["DATE"] != '0000-00-00' || $row["DATE"] != '0000-00-00 00:00:00' )
{
echo date("D j, M Y", strtotime($row["DATE"]));
}
else
{
echo 'not yet available';
}
You can shorten the if statement if you know how the value stored in database when date is not provided.
Upvotes: 0
Reputation: 86336
Make use of IF
if ($row["DATE"] != '' || $row["DATE"] != '0000-00-00')
{
echo date("D j, M Y", strtotime($row["DATE"]));
}
else
{
echo 'not yet available';
}
Upvotes: 2