The ideal would be to solve the SQL layer, which depends on the engine used.
For MySQL
Just do it right at select:
.--- converte de Unix para Timestamp, compativel com MySQL
|
SELECT ... WHERE DATE(FROM_UNIXTIME(last_used)) = CURRENT_DATE;
| |
'--- extrai a data, sem horas '--- compara com data de hoje
Solving with PHP
One way to do with PHP is to simply determine when the day begins in Unix Timestamp, and add 86399 seconds, and find values in this range, thus:
$hoje = time(); // Pega o timestamp do servidor já em segundos
$iniciododia = ( $hoje % 86400 ) * 86400; // "arredonda" para 0h00 do dia
$fimdodia = $iniciododia + 86399; // e obtem o 23h59m59 do dia
Applying to your query :
"SELECT * FROM {$table_prefix}_Users WHERE last_used BETWEEN $iniciododia AND $fimdodia"
|
retorna dados entre 0h00m00 e 23h59m59 ---'
The solution given is for other days, changing time()
for the desired day, but if you want only those of the current day, you can simplify even more:
$hoje = time(); // Pega o timestamp do servidor já em segundos
$iniciododia = ( $hoje % 86400 ) * 86400; // "arredonda" para 0h00 do dia
// ... desnecessário calcular o fim do dia para data atual ...
"SELECT * FROM {$table_prefix}_Users WHERE last_used >= $iniciododia"
If it's just the count
Remember that it is unnecessary to bring all the data if you want to know just the count. As your original query is, you are bringing all DB data to the desired date unnecessarily. Consider doing this:
"SELECT COUNT(*) FROM {$table_prefix}_Users WHERE last_used >= $iniciododia"
Then just get the single value returned instead of rowCount()
.