Answers.Body: <p>Was able to get the results I needed by using the following query: </p>
  
  <pre><code>        $users = \craft\elements\User::find()
              -&gt;where("extract(day from content.field_birthdate) = " . date('j'))
              -&gt;andWhere("extract(month from content.field_birthdate) = " . date('n'))
              -&gt;group('siteUsers')
              -&gt;status('active')
              -&gt;all();
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-18T21:02:01.517Z
Answers.LastActivityDate: 2019-09-18T21:02:01.517Z
Answers.UserDisplayName: PixelGarden
Body: <p>How does one retrieve users from Craft3 DB whose birthday is today?</p>
  
  <p>Birthdate field type is Date/Time. </p>
  
  <p>Have a working PHP/MySQL example, but unsure how to port this to Craft3 syntax.</p>
  
  <pre><code>$sql = 'SELECT 
              id,
              birthDate
           FROM 
              !
           WHERE 
              status = ?';
  
  
  $users = $db-&gt;getAll($sql, array( USERS_TABLE, 
                                    'active', 
                                    date('j'),
                                    date('n')
                                  ) 
                      );  
  </code></pre>
  
  <p>Craft plugin</p>
  
  <p><code>$users = \craft\elements\User::find()
             -&gt;group('siteUsers')
             -&gt;status('active')
             -&gt;all();</code></p>
  
Tags: <plugin-development><craft3><datetime>
Title: How to get users with birthday today in plugin/module?
ThreadText: # How to get users with birthday today in plugin/module?
  
  (Asked by: username_0 on 2019-09-18)
  
  How does one retrieve users from Craft3 DB whose birthday is today?
  
  Birthdate field type is Date/Time.
  
  Have a working PHP/MySQL example, but unsure how to port this to Craft3 syntax.
  
  ```
  $sql = 'SELECT 
              id,
              birthDate
           FROM 
              !
           WHERE 
              status = ?';
  
  $users = $db->getAll($sql, array( USERS_TABLE, 
                                    'active', 
                                    date('j'),
                                    date('n')
                                  ) 
                      );  
  
  ```
  
  Craft plugin
  
  `$users = \craft\elements\User::find()
  ->group('siteUsers')
  ->status('active')
  ->all();`
  
  **Tags:** plugin-development, craft3, datetime
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2019-09-18. Score: 2 | Accepted answer
  
  Was able to get the results I needed by using the following query:
  
  ```
          $users = \craft\elements\User::find()
              ->where("extract(day from content.field_birthdate) = " . date('j'))
              ->andWhere("extract(month from content.field_birthdate) = " . date('n'))
              ->group('siteUsers')
              ->status('active')
              ->all();
  
  ```
  
  
  ---
  
  