- bigint类型转换为datetime类型
- -- 假设 1164691264437 是 Java 里的“日期时间”:即:自1970-01-01 00:00:00以来的毫秒数
- /*
- getTime
- public long getTime()Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object.
-
- Returns:
- the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date.
- */
- mysql> select from_unixtime(1164691264437/1000);
- +-----------------------------------+
- | from_unixtime(1164691264437/1000) |
- +-----------------------------------+
- | 2006-11-28 13:21:04 |
- +-----------------------------------+
2、datetime类型转换为bigint类型
- -- 假设 "2011-05-31 23:59:59" 是 Java 里的“日期时间”:即:自1970-01-01 00:00:00以来的毫秒数
-
-
- mysql> select UNIX_TIMESTAMP('2011-05-31 23:59:59');
- +-----------------------------------+
- | from_unixtime(1306857599/1000) |
- +-----------------------------------+ |
将Int 转为varchar经常用 concat函数,比如concat(8,'0') 得到字符串 '80'
2、将varchar 转为Int 用 cast(a as signed) a为varchar类型的字符串
as 后 可跟参数:
二进制,同带binary前缀的效果 : BINARY
字符型,可带参数 : CHAR()
日期 : DATE
时间: TIME
日期时间型 : DATETIME
浮点数 : DECIMAL
整数 : SIGNED
无符号整数 : UNSIGNED
2、将varchar 转为Int 用 cast(a as signed) a为varchar类型的字符串
as 后 可跟参数:
二进制,同带binary前缀的效果 : BINARY
字符型,可带参数 : CHAR()
日期 : DATE
时间: TIME
日期时间型 : DATETIME
浮点数 : DECIMAL
整数 : SIGNED
无符号整数 : UNSIGNED