0

First of all im a starter,iam using eclipse. I want to add current date and time of login in to db and search a day and find out the time between login and logout. °What is the data type for the date colum in mysql ? °Is it necessary separate column for date and time ? °which one i want to import, java.util.date or java.sql.date ? °In Java code simple date format or calender is better ?

Advanced thanks.....

Ajnas Mam
  • 1
  • 1

1 Answers1

0

You might want to read this: Should I use field 'datetime' or 'timestamp'?

For example, if you have mysql populate the log record's date/time (using "DEFAULT CURRENT_TIMESTAMP" in your field definition), you will want to use timestamp. For certain situations where you fill a date value from your application, you may wish to use datetime. Be careful with timezones.

Here are the date functions in mysql: https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html

DATEDIFF(), for example, will calculate the number of days between two datetimes. If you use unix timestamps, you can use standard arithmetic between the values to find the number of seconds between them, and then calculate minutes, hours, days, etc. by dividing appropriately.

This answer is focused on how to handle the dates in mysql. Not enough info to provide guidance on java.

dlo
  • 1,580
  • 15
  • 24