select with datetime mssql

1

I'm trying to do a select in ms sql but I can not use datetime.

$dataInicio = \DateTime::createFromFormat('d/m/Y', $input['data_inicio'])->format('Y-m-d');

$result = \DB::select('Select * from PESAGEM where cast(databruto as date) = ? and ativo = 1')  ,[$dataInicio]); 

I tried to do it by querybuilder and I could not do it, for example if I use this query directly in the database I get return.

select * from pesagem where cast(datatara as date) = '2015-09-03' and ativo = 1

How would you do a query using datatime format?

    
asked by anonymous 04.09.2015 / 15:28

2 answers

1
SELECT 
   *
FROM
   Pesagem
WHERE 
   CONVERT(DATETIME, databruto, 103) = '01/10/2015' AND Ativo = 1
    
04.09.2015 / 21:52
0

Manipulate date with mysql would be

select datatara as date from pesagem where DATE(datatara) = '2015-09-03' and ativo = 1

or

select datatara as date from pesagem where DATE_FORMAT(datatara, '%Y-%m-%d') = '2015-09-03' and ativo = 1
    
04.09.2015 / 21:44