Proper syntax for date between where clause

Proper syntax for date between where clause

lintu98lintu98 Posts: 13Questions: 5Answers: 0

Hello Folks,

I need some help with the proper syntax to use on the server-side.

I have the following where clause -
WHERE table_date_column BETWEEN '2019-01-01' and '2019-12-31';

For which, on the data processing side, I added the following code which is not working -
$q->where( 'table_date_column', 'between '2019-01-01' and '2019-12-31'');

Could someone let me know what the correct syntax should be?

Thank you.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,808Questions: 85Answers: 406
    Answer ✓
    $q ->where( function ( $r ) {
        $r ->where( 'table_date_column', '2019-01-01', '>=' );
        $r ->where( 'table_date_column', '2019-12-31', '<=' );
    } );
    
  • lintu98lintu98 Posts: 13Questions: 5Answers: 0

    Thank you @rf1234 for your assistance.

This discussion has been closed.