In a MySQL table, I need to have two fields "StartTime" and "EndTime". My requirements are:
- If I do StartTime - EndTime, I need to get the time elapsed (when I subtract them I need to get time in seconds开发者_Go百科 or minutes or whatever).
- From "StartTime" I need to get the date (the date when my object was started).
So my question is in what format (or what type) should the fields "StartTime" and "EndTime" be in my MySQL table to meet the above two conditions? Also to which format in C# should I be retrieving the value from MySQL table?
MySQL offers two very similar data types DATETIME and TIMESTAMP. For many applications, either will work, but in some cases, one works better than the other...
http://dev.mysql.com/doc/refman/5.0/en/timestamp.html
http://dev.mysql.com/doc/refman/5.0/en/datetime.html
in general if you can use TIMESTAMP you should, as it is more space-efficient than DATETIME (it takes half the size of DATETIME).
here is a link to all the possible operations on the date type
http://dev.mysql.com/doc/refman/4.1/en/date-and-time-functions.html
Generally in MySql the DateTime will be in 'YYYY-MM-DD HH:MM:SS'
format. Refer to this to get the Required.
In c# you should use DateTime. I believe the mySQL equivalent is TimeStamp.
精彩评论