Compare dates in sql

0

In my bank I have the field with datetime current_timestamp in the access table. I need to display the amount that each device accessed the site, whether computer, ios or android, each time one of them accesses, the corresponding field receives 1, so I need to count on the day how many times the site has gained access from each device, problem is: how do I convert the datetime in the query to compare only the date without the hour? I did it that way but it worked yesterday, but the access data was from yesterday, today it's already been a problem.

<?php
    $select= "SELECT distinct CAST(data_acesso AS DATE) FROM tbl_acesso";
    $result_select= $conn->query($select);
    while($col = mysqli_fetch_assoc($result_select)):
        $data = $col['data'];
        $data_create = date_create($data);
        $data_format = date_format($data_create, "Y-m-d");

        //selecionando site
        $selectSite = "SELECT site FROM tbl_acesso WHERE CAST(data_acesso as DATE) = '$data_format' AND site IS NOT NULL ";
        $resultadoSite = $conn->query($selectSite);
        $site = mysqli_num_rows($resultadoSite);

        //selecionando ios
        $selectIos = "SELECT ios FROM tbl_acesso WHERE CAST(data_acesso as DATE) = '$data_format' AND ios IS NOT NULL";
        $resultadoIos = $conn->query($selectIos);
        $ios = mysqli_num_rows($resultadoIos);

        //selecionando android
        $selectAndroid = "SELECT android FROM tbl_acesso WHERE CAST(data_acesso as DATE) = '$data_format' AND android IS NOT NULL";
        $resultadoAndroid = $conn->query($selectAndroid);
        $android = mysqli_num_rows($resultadoAndroid);
?>
    
asked by anonymous 31.10.2018 / 15:37

2 answers

1

The data must be a datetime or smalldatetime, so it saves both values. You can do this:

convert(date,@data1) = convert(date,@data2) 

So you compare ignoring hours because both are converted from DATETIME to DATE.

I hope I have helped.

    
31.10.2018 / 16:51
0

I decided to do this here guys

SELECT DATE_FORMAT(data_acesso, '%Y-%m-%d') AS data_acesso FROM tbl_acesso;

In sgbd it worked, but in php it did not go because it needed an alias.

    
01.11.2018 / 13:40