PHP lib CURDATE() issue

PHP lib CURDATE() issue

rpmccormickrpmccormick Posts: 107Questions: 13Answers: 0
edited December 2022 in Editor

Regarding this Google result (closed thread):
https://datatables.net/forums/discussion/61200/current-date-problem

This is my working SQL:
AND DATE(TimeSpan_Start)=CURDATE()

This solution works:
$Editor->where('DATE(TimeSpan_Start)', date('Y-m-d'), '=');

But I would prefer to use MySQL... why doesn't this work:
$Editor->where('DATE(TimeSpan_Start)', 'CURDATE()', '=', false);

Time-Zones for different Web Servers vs. SQL Server make things complicated.

Replies

  • allanallan Posts: 61,669Questions: 1Answers: 10,096 Site admin

    It doesn't work like that, because the Editor->where() method doesn't have the same signature as Query->where(). Specifically there isn't the optional binding parameter. Instead, do:

    ->where(function ($q) {
      $q->where('DATE(TimeSpan_Start)', 'CURDATE()', '=', false);
    }
    

    Using an anonymous function like that gives you access to the underlying Query->where() method which does allow you to set the binding option.

    Allan

Sign In or Register to comment.