I’m on the fence about these two options I’ve been considering:
Option A: Using a DATETIME field and converting it to the xsd format after pulling it from the field
Option B: Using a VARCHAR field and converting it to the xsd format before inserting it into the field
Maybe both options are equally as efficient, but maybe there is an Option C that I haven’t considered yet.
If it makes a difference, its a requirement for a table that I’m making. The data definition for the field reads:
A date in xsd:dateTime format: [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm]
Example: 2001-10-26T21:32:52
I’m going to be using php to both read & write from this database and I know there are a plethora of date/time functions for both mysql and php alike.
What’s the best datatype and method of read/write to use in this situation?
It depends on what you need to do with that column, and what you are getting into it.
For example if you have to manipulate the value in a query then a
DATETIMElooks good, but then if you need to output it back to XSD, is the information in the time zone relevant? For even if you read it correctly withCONVERT_TZ(), the datetime column will lose you that information.So if you need the “point in time”, convert to UTC and store it as a datetime. If you also need to regenerate it identically, store the TZ in a secondary column.
If you do nothing with the information, then keep it as
VARCHAR– you’ll still be able to change idea down the line. The “datetime column only” is the only choice you won’t be able to walk away from.