Compare two hours (TimeStamp) MySql Java

1

I must compare 2 hours one that is already registered from the database and the current time, I have been told that I can use the in MySQL make me return a true or false and minutes difference, then in java I should receive what returns and according to what it is to perform an action. Could someone give me an example of this? Thank you very much.

    
asked by Lina Cortés 21.05.2016 в 02:23
source

2 answers

1

You can also use the TIMESTAMPDIFF function from MySQL. To compare the minutes:

SELECT timestampdiff(MINUTE, nombre_columna, now()) <= 120
  FROM tabla
 WHERE otra_columna = algun_valor

Return 1 if 120 minutes have not yet passed or 0 otherwise, depending on the value of nombre_columna ( TIMESTAMP ) to the current time.

-------
NOTE : To use this MySQL function in JPA, a native SQL statement ( createNativeQuery ) can be used.

    
answered by 21.05.2016 / 20:06
source
0
SELECT unix_timestamp( columna ) - unix_timestamp( sysdate() ) AS diferencia FROM tabla;

will not give you a true or false but the difference, but with that you process it in the java

    
answered by 21.05.2016 в 14:07