How to check if a DateTime attribute is set? I have a optional dateFinished attribute in my Record:

protected function defineAttributes()
{
    return array(
        ...
        'dateFinished'  =&gt; AttributeType::DateTime,
        ...
    );
}


Some Records have it set to a DateTime other have it set to null (default).

To prevent Twig errors I tried using the is defined test:

{{ log.dateFinished is defined ? log.dateFinished|date('m.d.y - H:m'|t) : '-'}}


But this doesn't work, I'm getting the typical "Scope error". After taking a look at the dump() it looks that even a null value is getting defined:

  ["dateFinished"]=&gt;
  object(Craft\DateTime)#2670 (3) {
    ["date"]=&gt;
    string(19) "2014-07-15 17:48:25"
    ["timezone_type"]=&gt;
    int(1)
    ["timezone"]=&gt;
    string(6) "+00:00"
  }

  ....

  ["dateFinished"]=&gt;
  array(2) {
    ["column"]=&gt;
    string(8) "datetime"
    ["type"]=&gt;
    string(8) "datetime"
  }


I tried to solve this by "Check(ing) if a variable is a date with Twig":

{{ log.dateFinished is defined and log.dateFinished.timestamp is defined ? log.dateFinished|date('m.d.y - H:m'|t) : '-'}}


But this doesn't make a difference, I'm still getting the "Scope error". Any ideas?
You shouldn't be returning a record instance to your templates directly. That can lead to all sorts of badness like templates being able to update the database themselves.

Have your plugin's service populate a Mailer_LogModel with just the attributes you want to expose to your template and return that.  Pretty sure after you do that, a simple:

{% if log.dateFinished %}


will work.