How can I compare if a date is less than the current server date?

0

How can I compare dates entered in the database with the current date of the server and know if the date in the database is less than the current date or server to perform the next action. something like that is what I want to do

"select * from publi where carrerae LIKE '%Informatica%' AND fecha (es menor a) date(y-m-d) ORDER BY id DESC"
    
asked by ivanrangel 14.03.2017 в 04:43
source

2 answers

0

I will venture an answer. In MySQL , To obtain records whose date is less than the current system date, the CURDATE function is used.

If your fecha field is really a date or at least it can be interpreted as such, then the records you want to obtain come from:

SELECT * 
FROM publi 
WHERE carrerae LIKE '%Informatica%' 
AND fecha < CURDATE() 
ORDER BY id DESC
    
answered by 14.03.2017 / 23:59
source
0

Try this, it works for me

    <?php
    $datetime1 = date_create(date('Y-m-d')); //fecha actual  
    $datetime2 = date_create($row['FechaDB']); //fecha de db  
    $interval = date_diff($datetime1, $datetime2,false);  
    $dias = intval($interval->format('%R%a'));  

    if ($dias < 0) {
        echo "Mayor 1";
    }else if ($dias == 0) {
        echo "iguales";
    }else if ($dias > 0) {
        echo "Mayor 2";
    }
    ?>
    
answered by 14.03.2017 в 05:21