问题
我需要从实际的 datetime 格式字段 date 安全地转换 mySQL 数据库表 MYTABLE 中的日期格式:例如2013-09-10 12:43:03,与其 unix 时间戳 等效:1378816983,不会影响数据库中已有的数千篇文章。
我正在使用 PHP、mySql、Drupal。
我的方法
我的脚步
将表字段类型从日期时间更改为时间戳[完成]
转换实际内容类型字段:timestamp [DONE]
使用 PHP strtotime() 或 MYSQL:UNIX_TIMESTAMP(date) 转换 4 个表中的现有文章数据字段
我需要有关 PT.3 的帮助
一个。对pt的算法有一点帮助。 3:
例如
loop over all 4 tables {
- create a new column date2 of type: int (or datetime?)
- copy all dates from date to date2 passing them through strtotime()
- delete column date
- rename column date2 to column date
}
最佳答案
- 备份表
- 检查备份是否正确安全
- 将表字段类型从 datetime 更改为 varchar
- 更新表 set field=unix_timestamp(field)
- 将表字段类型从 varchar 更改为 int
但是我根本不会做这样的转换
关于PHP:安全地将 mySQL 中的字段日期从 'datetime' 转换为 'unix timestamp' 而不会丢失数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18739648/