Query Date()

Query Date()

antoniocibantoniocib Posts: 277Questions: 62Answers: 1
edited October 2020 in Free community support

Hi guys I have a problem I have two datetime that I have to check to use POST so to load the data in the table only which have different times and the request to format Datetime in Date I can't do it serverside, can you help me the query is the following how should I write it in Editor?

SELECT * from scrivania WHERE
Date(scarico_bo) = "2020-10-15" and Date(delivery) = "2020-10-15" 
OR 
Date(delivery) = "2020-10-15" 
OR
 Date(scarico_bo) = "2020-10-15" 

in the Editor manual i did not find anything to do formatting from DATE to DATETIME in clientside

Answers

  • rf1234rf1234 Posts: 2,950Questions: 87Answers: 416
    edited October 2020

    According to my limited knowledge of Boolean algebra this:

    SELECT * from scrivania WHERE
    Date(scarico_bo) = "2020-10-15" and Date(delivery) = "2020-10-15"
    OR
    Date(delivery) = "2020-10-15"
    OR
     Date(scarico_bo) = "2020-10-15"
    

    can be written like this:

    SELECT * from scrivania WHERE
    Date(delivery) = "2020-10-15"
    OR
     Date(scarico_bo) = "2020-10-15"
    

    The logical AND is evaluated before all of the ORs. Hence it is like putting a bracket around this

    ( Date(scarico_bo) = "2020-10-15" and Date(delivery) = "2020-10-15" )

    It is sufficient for the WHERE clause to return true if either "scarico_bo" is "2020-10-15" or "delivery". It is irrelevant whether both equal "2020-10-15".

    But anyway ... I took a look at the more complex WHERE clause and wrote it in Editor syntax below.

    if you take a look at this in the docs https://editor.datatables.net/manual/php/conditions#Complex-usage
    you should find what you need:

    The WHERE clause could look something like this:

    $editor->where( function ( $q ) {
        $q ->where( function ( $r ) { //put brackets around following
            $r->where( 'DATE(scarico_bo)', $_POST['scarico_bo'] );
            $r->where( 'DATE(delivery)', $_POST['delivery'] );
        } );
        $q ->or_where( 'DATE(delivery)', $_POST['delivery'] );
        $q ->or_where( 'DATE(scarico_bo)', $_POST['scarico_bo'] );    
    } );
    
This discussion has been closed.