Limit ElementAPI results with custom date/time field What is the proper syntax in the ElementAPI 'criteria' configuration settings for limiting entries based on custom start and end date/time fields. I can't use the default postDate and expiryDate due to localization requirements.

I have the proper syntax working in my twig template:

.startDateTime('&lt;=' ~ now.date,':empty:').endDateTime('&gt;=' ~ now.date,':empty:')

How can I mimic this same logic in the ElementAPI config settings? This is what I have so far. It doesn't throw any php errors but doesn't return the results I am expecting:

'criteria' =&gt; [
    'section' =&gt; 'mySection', 
    'type' =&gt; 'mySectionType',
    'startDateTime' =&gt; '&lt;=' . date("Y-m-d H:i:s") . ', :empty:',
    'endDateTime' =&gt; '&gt;=' . date("Y-m-d H:i:s") . ', :empty: '
],
After some exploration and trial and error, I was able to find a solution. Ultimately there are two problems:


startDateTime, endDateTime and php’s date() function were not returning the same timezone date &amp; time.
The correct formatting for matching multiple values needs to be in an array.




The fix:

At the top of my elementapi.php file I added this line to make sure php’s date() function returns the same timezone craft has been set to in the admin config.

date_default_timezone_set(craft()-&gt;timezone);

Then I reformatted my criteria settings as such:

'criteria' =&gt; [
    'section' =&gt; 'mySection', 
    'type' =&gt; 'mySectionType',
    'startDateTime' =&gt; ['&lt;=' . date("Y-m-d H:i:s.u"), ':empty:'],
    'endDateTime' =&gt; ['&gt;=' . date("Y-m-d H:i:s.u"), ':empty:']
],