Monday, February 21, 2011

Compare two times

hi everyone, i want to compare between two times the first one is getting by the resultset of an sql query like the following:

res = req.executeQuery("SELECT SEC_TO_TIME(SUM(TIME_TO_SEC(timespent))) FROM dailytimesheet where trackingdate=CURRENT_DATE and matricule=36;");
res.first();     
{
    retour.append("<td><label  style=\"background-color:#09F\" style=\"font:Verdana, Geneva, sans-serif\"  style=\"font-size:16px\"> Total Hours</label><td>"+res.getString(1)+ "</td>");   

and the second time is: 07:30:00

so i want to display a message if the time containing in the res.getString(1) is bellow the time 07:30:00. i dont know how to achieve the comparison.

From stackoverflow
  • you would have to create a Date/Time from the string and then diff it with a Date/Time of 07:30:00

    in java: date.compareTo(otherdate) will return -1 if smaller, 0 if equal, +1 if higher

    Redlab : another option is to split the string on hours, minutes, seconds and calculate it yourself
    Unreason : third option is to do it in SQL, http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

0 comments:

Post a Comment