Today, there is a problem, that is, when a project design table, the time in 20160101123596 in this form, the varchar into the database.
Today to write a SQL, query a report, the condition is to filter this time, but varchar type, how to do?
After Google gets this answer, now summarize
CAST (field as type);
field is a database field, can be any type, and type is the type you want to convert, type has the following
- Binary, with binary prefix effect: binary
- Character type, with parameters: CHAR ()
- Date: Date
- Time:
- DateTime Date/Time type
- Floating point number: DECIMAL
- Integer: Signed
- unsigned integer: UNSIGNED
I was excited to see this, and I wrote a SQL test:
Select cast ('20151025162337'asDATETIME);
Successful, converted directly into a date format.
Select CAST ('123' as signed) + 2
Successful, shown as 125.
Since this is OK, then for a data table, then there is no problem, such as the next SQL is also written out
Select *,CASTasDATETIME as from table name where hx_time > ' 2015-05-01 '
MySQL conversion type