Answers.Body: <p>There might be another (better) way to do this, but here's an example of adding <code>lastInvalidLoginDate</code> as a column to the Users element index:</p>
  <pre><code>\yii\base\Event::on(
      \craft\elements\User::class,
      \craft\elements\User::EVENT_REGISTER_TABLE_ATTRIBUTES,
      function(\craft\events\RegisterElementTableAttributesEvent $e) {
          $e-&gt;tableAttributes['lastInvalidLoginDate'] = [
              'label' =&gt; &quot;Last Invalid&quot;
          ];
      }
  );
  \yii\base\Event::on(
      \craft\elements\db\UserQuery::class,
      \craft\elements\db\UserQuery::EVENT_BEFORE_PREPARE,
      function (\yii\base\Event $event) {
          $event-&gt;sender-&gt;query-&gt;select['users.lastInvalidLoginDate'] ='users.lastInvalidLoginDate';
      }
  );
  </code></pre>
  <p>Hopefully that helps!</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-09-27T12:44:51.927Z
Answers.LastActivityDate: 2022-09-27T12:44:51.927Z
Answers.UserDisplayName: revlis
Body: <p>I'm wanting to show a user's last invalid login date within the control panel. No matter the value in the database, it comes back as NULL, unless I try formatting it as a date, then the current date and time are returned. Any ideas on why? I'm using <code>{{ user.lastInvalidLoginDate }}</code>, and pulling other info through <code>{{ user }}</code> works just fine.</p>
  
Tags: <users><datetime><login>
Title: LastInvalidLoginDate returning NULL, or current date if formatted
ThreadText: # LastInvalidLoginDate returning NULL, or current date if formatted
  
  (Asked by: username_0 on 2022-09-19)
  
  I'm wanting to show a user's last invalid login date within the control panel. No matter the value in the database, it comes back as NULL, unless I try formatting it as a date, then the current date and time are returned. Any ideas on why? I'm using `{{ user.lastInvalidLoginDate }}`, and pulling other info through `{{ user }}` works just fine.
  
  **Tags:** users, datetime, login
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-09-27. Score: 0 | Accepted answer
  
  There might be another (better) way to do this, but here's an example of adding `lastInvalidLoginDate` as a column to the Users element index:
  
  ```
  \yii\base\Event::on(
      \craft\elements\User::class,
      \craft\elements\User::EVENT_REGISTER_TABLE_ATTRIBUTES,
      function(\craft\events\RegisterElementTableAttributesEvent $e) {
          $e->tableAttributes['lastInvalidLoginDate'] = [
              'label' => "Last Invalid"
          ];
      }
  );
  \yii\base\Event::on(
      \craft\elements\db\UserQuery::class,
      \craft\elements\db\UserQuery::EVENT_BEFORE_PREPARE,
      function (\yii\base\Event $event) {
          $event->sender->query->select['users.lastInvalidLoginDate'] ='users.lastInvalidLoginDate';
      }
  );
  
  ```
  
  Hopefully that helps!
  
  
  ---
  
  