CURRENT_DATE PROBLEM

CURRENT_DATE PROBLEM

antoniocibantoniocib Posts: 200Questions: 41Answers: 1
edited March 27 in Free community support

Hi guys,
to bypass the "datapicker" issue that I'm not able to import into my code, because I'm ignorant and ashamed of it, I thought of a solution to this code:

Editor::inst( $db, 'scrivania1', 'id' )
    ->fields(
        Field::inst( 'ddt' ),
        Field::inst( 'cliente' ),
        Field::inst( 'carico' ),
        Field::inst( 'destinazione' ),
        Field::inst( 'pr' ),
        Field::inst( 'scarico' ),
        Field::inst( 'scarico_m' ),
        Field::inst( 'data_di_scarico' )
            ->validator( Validate::dateFormat( 'd/m/Y' ) )
            ->getFormatter( Format::dateSqlToFormat( 'd/m/Y' ) )
            ->setFormatter( Format::dateFormatToSql( 'd/m/Y' ) ),
        Field::inst( 'epal' ),
        Field::inst( 'ind' ),
        Field::inst( 'perd' ),
        Field::inst( 'dati_di_scarico' ),
        Field::inst( 'drit' ),
        Field::inst( 'trit' ),
        Field::inst( 'dlinea' ),
        Field::inst( 'tlinea' ),
        Field::inst( 'note' ),
        Field::inst( 'active' )
        ->setFormatter( function ( $val, $data, $opts ) {
                            return ! $val ? 0 : 1;
                    } )
    )

I would add this clause:

->where ('data_di_scarico' = Current_Date)

But on phpmyadmin it works for me and from here it doesn't, why?

And return me the errorr TN/1

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 1,766Questions: 51Answers: 257

    https://editor.datatables.net/manual/php/conditions

    ->where ('data_di_scarico', 'Current_Date', '=', false)
    
    
  • allanallan Posts: 52,624Questions: 1Answers: 8,050 Site admin

    And return me the errorr TN/1

    When you read and follow the instructions at that tech note, what do you see the server responding with. I would expect it to be an error message explaining what the issue is.

    It's because your PHP is not valid. First Current_Date above is a _constant (which you presumably don't have defined) and second you are attempting to assign it to a string as a value in a method call parameter.

    What I would suggest is that you get the current date using PHP's date() method. e.g.:

    ->where('data_di_scarico', date('Y/m/d'))
    

    Allan

  • rf1234rf1234 Posts: 1,766Questions: 51Answers: 257
    Answer ✓

    @allan, "Current_Date" is MySQL syntax and unknown to PHP. It is the same as MySQL "curdate()".

    Both MySQL-functions (or whatever they are called) return this for today: 2020-03-28

    So I would rewrite your line like this to achieve the same result:

    ->where('data_di_scarico', date('Y-m-d'))
    
  • antoniocibantoniocib Posts: 200Questions: 41Answers: 1

    Ty @allan and @rf1234 u are the best!

Sign In or Register to comment.