select SQL fields after a certain date

0

I have a table that has daily records (test table) for 2 years

I want to get the result from a certain generated by php date "$ last_periodo_date"

$last_periodo_date = date("Y-m", strtotime("- 1 month"))."-25" ;

$ last_periodo_date always returns me on the 25th of last month in year-month-day format (example 2018-06-25)
Note: $ User_ID is a field that I compare on the side to refer to specific users

$sql_asistencia = "SELECT * FROM asistencia where id_usuario=$Id_usuario AND asistencia ='1' AND fecha > $last_periodo_date  ";

here everything works fine 'AND date > $ last_periodo_date '

$params = array();
$options =  array( "Scrollable" => SQLSRV_CURSOR_KEYSET );
$stmt = sqlsrv_query( $conn, $sql_asistencia2 , $params, $options );

This part has to do with my SQL server

$resultado = sqlsrv_num_rows( $stmt );

This is my result but it is not delivering results, if I withdraw from the seect it shows all the results correctly, but when I show the date it does not

    
asked by claus 30.07.2018 в 19:59
source

1 answer

1

You should convert the variable date php to date sql .-

$sql_asistencia = "SELECT * FROM asistencia where id_usuario=$Id_usuario AND asistencia ='1' AND fecha > convert(datetime, $last_periodo_date, 111) ";

111 It's the format yyyy / mm / dd

    
answered by 30.07.2018 в 20:12