Reputation: 7723
If I have a string,
2016-02-24T18:12:24-0500
Can it be directly stored in MySql as a Datetime or Timestamp, or should it be split into two columns before loading and stored as Date and Time.
When retrieving data from database, I need to sort the record set based on date and time. If it is possible store as one datetime, can it be used to directly sort records retrieved?
I will use this in Java and JPA programs.
Edited:
I have a text file to be prepared like this:
1 A 2016-02-24T18:12:24-0500
2 B 2016-02-25T18:12:24-0500
3 C 2016-02-26T18:12:24-0500
Then I am going to use this statement to load data to database:
LOAD DATA LOCAL INFILE 'data.txt' INTO TABLE UserData
Can this be directly loaded into the database table UserData?
Upvotes: 0
Views: 63
Reputation: 1723
Using a single field with both parts or two fields really depends on what you are going to do with the information afterwards.
If you are going to do sorting normally it will be easier if you just use one field.
Your String needs to be converted to a Java object before storage. Just convert it to a java.sql.Timestamp before sending to the database.
Upvotes: 1