Reputation: 3
I know that this is longed asked question but still I can't find an answer.
I have a fix time in and out in my database. Also I have date_in and date_out in separate columns. All the data in my database come from csv which is in that exact format. Can I concatenate (time_in and date_in) and (time_out and date_out) and put them in a designated column which is in timestamp format?
I'm making a import and export of csv in which those info below is concern. So far I can export it but my import doesn't work well. I use the phpmyadmin csv load data to import. Can't get my head in importation of dates and times coz other data mess up in my database.
Note: total_hrs is not included in the csv which means that it is already in my database. And it doesn't have a value so basicaly I will provide values for that in my script.
Example:
id | time_in | time_out | date_in | date_out | total_hrs
1 | 9:30pm | 7:30am | 2013-12-01 | 2013-13-01 | ?
This should have a 10 hours elapsed time.
So basically it also has a different date. I'm confused whether I need to convert the time in timestamps or something similar to get the time difference or I also need to have the date as well to be a basis in getting the difference between the two time??Any suggestions.
Upvotes: 0
Views: 86
Reputation: 6625
use timestamps in mysql:
INSERT INTO tblTimes (timein) VALUES (NOW());
UPDATE tblTimes SET timeout = NOW() WHERE id=$someid;
to compare, see https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_timediff
Upvotes: 0
Reputation: 629
If you have the date you should use timestamps. They're easier to compare.
Upvotes: 0
Reputation: 1178
It could be also 34, 58,.. hours. I advise you to store timestamps, if you will need pretty display of it you can just use print (or smth similiar) function in MySql.
Upvotes: 1