-1

Here is the scenario :

I have a form :

| Check in time |

| Check out time |

E.G i do :

Check in = 15:30

Check out = 16:30

Questions :

  1. How can i store the times in my mysql Table which is styled in "datetime" (YY-MM-DD 10:45:48)

Will this work ?:

Date datum = new Date();
//today declared as today
 datum.setDay(today);
 datum.setMonth(today);
 datum.setYear(today);

 datum.setMinute(30);
 datum.setHour(15);

and then " insert date='date' "

2nd :

How can I Delete via MYSQL the row which Time is Smaller than current:

Will this work?

DELETE FROM adminLoginLog WHERE `date` > NOW() );

Note im useing MysqlI <--- not mysql

user3110458
  • 374
  • 5
  • 17
  • Are you manually building the SQL statement, or are you using JDBC's [`PreparedStatement`](http://docs.oracle.com/javase/7/docs/api/java/sql/PreparedStatement.html) interface? `PreparedStatement`s are created via the `Connection` object's [`prepareStatement`](http://docs.oracle.com/javase/7/docs/api/java/sql/Connection.html#prepareStatement(java.lang.String)) methods. See: [Using Prepared Statements](http://docs.oracle.com/javase/tutorial/jdbc/basics/prepared.html) for more info. – Powerlord Apr 28 '14 at 15:18
  • The reason I ask is because PrepareStatement has methods for sending various datatypes to the server based on the DB driver. – Powerlord Apr 28 '14 at 15:22

1 Answers1

1
  1. In Java, use java.sql.Timestamp to store the date and time of your field. Also, build your Date using Calendar object, do not update fields in java.util.Date directly. Note that using new Date() will automatically create a java.util.Date with the current date and time, no need to do any special additional effort.

  2. Try this query (assumming this is what you want):

    DELETE FROM adminLoginLog WHERE `date` BETWEEN CURDATE() AND NOW()
    

    In case you only need the current time (really odd), use CURTIME():

    DELETE FROM adminLoginLog WHERE `date` < CURTIME()
    
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332