If (empty(DATETIME))?

If you fetch a MySQL DATETIME that’s not set,

Output: 0000-00-00 00:00:00

if (empty($date)) { echo 1; }
if (!isset($date)) { echo 2; }

How do I check if the Date isn’t a real date?


See the first comment.

Hey, Thanks man ! Sorry for my delayed message I was installing Apache :slight_smile:

Use some method instead:

function formatDate($format,$dateStr) {
  if (trim($dateStr) == '' || substr($dateStr,0,10) == '0000-00-00') {
    return '';
  $ts = strtotime($dateStr);
  if ($ts === false) {
    return '';
  return date($format,$ts);

nice function this one goes in my function archives thnx man you look good !

Er, that’s the function in the first comment from the manual entry for strtotime (in my first post). So unless that comment in the manual was PHPycho’s, then no, he doesn’t “look good”.

concept matters.
Just take the good concepts. :slight_smile: