Answers.Body: <p>If you want the latest of both, unless I'm missing something, you should just be able to query on <code>dateUpdated</code>. </p>
  
  <p>When you create an entry the first time, its <code>dateUpdated</code> gets set to the same date as the <code>dateCreated</code>... So if you query your entries on <code>dateUpdated</code> only, you will get all entries created + updated in your time frame I guess.</p>
  
  <p>As far as code goes, this should do it:</p>
  
  <pre><code>return [
      'endpoints' =&gt; [
          'entries.json' =&gt; function() {
              $timeframe = (new \DateTime('1 day ago'))-&gt;format(\DateTime::ATOM);
              return [
                  'elementType' =&gt; Entry::class,
                  'criteria' =&gt; [
                      'section' =&gt; 'entries',
                      'dateUpdated' =&gt; '&gt;=' . $timeframe,
                  ],
                  'transformer' =&gt; function(Entry $entry) {
                      return [
                          'title' =&gt; $entry-&gt;title,
                          'url' =&gt; $entry-&gt;url,
                      ];
                  },
              ];
          },
      ]
  ];
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-15T21:18:26.057Z
Answers.Text: I didn't even think of that. That will probably work fine for my situation then.
Answers.UserDisplayName: Erik
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-01-15T20:14:44.250Z
Answers.LastActivityDate: 2019-01-15T20:14:44.250Z
Answers.UserDisplayName: Oli
Body: <p>Using the Element API is there a way to get entries by <code>dateUpdated</code> OR <code>dateCreated</code> within the last whatever time, say day?</p>
  
  <p>Or a way to get the entry IDs for both of those criteria then do a query based on just the IDs from both results?</p>
  
  <p>I want to get any entry that was created or updated within the last day using the API but can't quite get it.</p>
  
Tags: <plugin-elementapi>
Title: Use conditional for Element API results?
ThreadText: # Use conditional for Element API results?
  
  (Asked by: username_0 on 2019-01-14)
  
  Using the Element API is there a way to get entries by `dateUpdated` OR `dateCreated` within the last whatever time, say day?
  
  Or a way to get the entry IDs for both of those criteria then do a query based on just the IDs from both results?
  
  I want to get any entry that was created or updated within the last day using the API but can't quite get it.
  
  **Tags:** plugin-elementapi
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-01-15. Score: 3 | Accepted answer
  
  If you want the latest of both, unless I'm missing something, you should just be able to query on `dateUpdated`.
  
  When you create an entry the first time, its `dateUpdated` gets set to the same date as the `dateCreated`... So if you query your entries on `dateUpdated` only, you will get all entries created + updated in your time frame I guess.
  
  As far as code goes, this should do it:
  
  ```
  return [
      'endpoints' => [
          'entries.json' => function() {
              $timeframe = (new \DateTime('1 day ago'))->format(\DateTime::ATOM);
              return [
                  'elementType' => Entry::class,
                  'criteria' => [
                      'section' => 'entries',
                      'dateUpdated' => '>=' . $timeframe,
                  ],
                  'transformer' => function(Entry $entry) {
                      return [
                          'title' => $entry->title,
                          'url' => $entry->url,
                      ];
                  },
              ];
          },
      ]
  ];
  
  ```
  
  > **Comments:**
  > **username_0**: I didn't even think of that. That will probably work fine for my situation then.  
  
  ---
  
  