mysql时间属性之时间戳和datetime之间的转换
一、datetime转换为时间戳
方案一:强制转换字段类型
use`nec`;
SET SQL_SAFE_UPDATES=0;
ALTER TABLE `usr_user_info` CHANGE COLUMN `registerTime` `registerTime` BIGINT(20) NOT NULL COMMENT '注册时间' ,
ALTER TABLE `usr_user_info` CHANGE COLUMN `lastLoginTime` `lastLoginTime` BIGINT(20) NULL DEFAULT NULL COMMENT '最后登录时间' ;
UPDATE `usr_user_info` SET `lastLoginTime` = unix_timestamp(`lastLoginTime`);
UPDATE `usr_user_info` SET `registerTime` = unix_timestamp(`registerTime`);
方案二:增加临时列
--
-- table alter for usr_user_info
--
/*增加字段*/
use `nec`;
ALTER TABLE `usr_user_info` ADD COLUMN tempRegisterTime BIGINT(20) NULL ;
ALTER TABLE `usr_user_info` ADD COLUMN tempLastLoginTime BIGINT(20) NULL ; /*进行时间转化,并复制列*/
UPDATE usr_user_info SET tempRegisterTime=unix_timestamp(registerTime);
UPDATE usr_user_info SET tempLastLoginTime=unix_timestamp(lastLoginTime); /*删除原有字段*/
ALTER TABLE usr_user_info
DROP registerTime,DROP lastLoginTime; /*更新临时字段名称*/
ALTER TABLE usr_user_info CHANGE tempRegisterTime registerTime BIGINT(20) NOT NULL COMMENT '注册时间';
ALTER TABLE usr_user_info CHANGE tempLastLoginTime lastLoginTime BIGINT(20) COMMENT '最近登录时间';
二、时间戳转换成datetime
这个谷歌一堆教程,主要涉及'FROM_UNIXTIME(registerTime )'这个转换函数,不仔细详述了
mysql时间属性之时间戳和datetime之间的转换的更多相关文章
- MYSQL时间类别总结: TIMESTAMP、DATETIME、DATE、TIME、YEAR
总结背景: 对于MYSQL数据库日期类型或多有了解, 但并很清晰其中一些规则. 基本都是面向浏览器编码, 这实质上也是一种方式. 但期间遇到两个问题: 时常遇到建表中出现多个datetime或者ti ...
- Mysql时间存储类型优缺点?DATETIME?TIMESTAMP?INT?
TIMESTAMP 4个字节储存;值以UTC格式保存;.时区转化 ,存储时对当前的时区进行转换,检索时再转换回当前的时区. DATETIME 8个字节储存;实际格式储存;与时区无关;datetime ...
- python中的时间戳和格式化之间的转换
import time #把格式化时间转换成时间戳 def str_to_timestamp(str_time=None, format='%Y-%m-%d %H:%M:%S'): if str_ti ...
- 【翻译】Flink Table Api & SQL —Streaming 概念 ——时间属性
本文翻译自官网: Time Attributes https://ci.apache.org/projects/flink/flink-docs-release-1.9/dev/table/str ...
- python中时间戳,datetime 和时间字符串之间得转换
# datetime时间转为字符串def Changestr(datetime1): str1 = datetime1.strftime('%Y-%m-%d %H:%M:%S') retu ...
- python 有关datetime时间日期 以及时间戳转换
直接上代码 其中有注释 #coding=utf-8 import time import datetime def yes_time(): #获取当前时间 now_time = datetime.da ...
- Python时间、日期、时间戳之间的转换
一.字符串与为时间字符串之间的互相转换 方法:time模块下的strptime方法 a = "2012-11-11 23:40:00" # 字符串转换为时间字符串 import t ...
- python 时间字符串和时间戳之间的转换
https://blog.csdn.net/qq_37193537/article/details/78987949 1.将字符串的时间转换为时间戳 方法: a = " ...
- mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间
mysql取出现在的时间戳和时间时间戳转成人类看得懂的时间,我们在mysql里面他封装了一个内置的时间戳转化的函数,比如我们现在的时间戳是:1458536709 ,"%Y-%m-%d&quo ...
随机推荐
- 【贪心】SOJ 13983
SOJ 13983. Milk Scheduling 这是比赛题,还是作死的我最讨厌的英文题,题目大意就是有n头奶牛,要在喂奶截止时间前给他喂奶并得到相应的含量的牛奶. 一开始的想法就是挑选截止日期的 ...
- scrapy爬虫笔记(一)------环境配置
前言: 本系列文章是对爬虫的简单介绍,以及教你如何用简单的方法爬取网站上的内容. 需要阅读者对html语言及python语言有基本的了解. (本系列文章也是我在学习爬虫过程中的学习笔记,随着学习的深入 ...
- MySQL每天自动增加分区
有一个表tb_3a_huandan_detail,每天有300W左右的数据.查询太慢了,网上了解了一下,可以做表分区.由于数据较大,所以决定做定时任务每天执行存过自动进行分区. 1.在进行自动增加分区 ...
- Areas on the Cross-Section Diagram
Areas on the Cross-Section Diagram Aizu - ALDS1_3_D Areas on the Cross-Section Diagram 地域の治水対策として.洪 ...
- log4j mongoDB配置
log4j.rootCategory=INFO, stdout log4j.appender.stdout=org.springframework.data.document.mongodb.log4 ...
- asp.net identity 3.0.0 在MVC下的基本使用 序言
本人也尚在学习使用之中,错误之处请大家指正. 开发环境:vs2015 UP1 项目环境:asp.net 4.6.1 模板为:asp.net 5 模板 identity版本为:asp.n ...
- Thinking in Java——笔记(17)
Containers in Depth Full container taxonomy You can usually ignore any class that begins with " ...
- 看懂SqlServer查询计划【转】
原文链接:http://www.cnblogs.com/fish-li/archive/2011/06/06/2073626.html 开始 SQL Server 查找记录的方法 SQL Server ...
- Redis 3.2 Linux 环境集群搭建与java操作
redis 采用 redis-3.2.4 版本. 安装过程 1. 下载并解压 cd /usr/local wget http://download.redis.io/releases/redis-3. ...
- web app 自适应方案总结 关键字 弹性布局之rem
关于rem,主要参考文档 1.腾讯ISUX (http://isux.tencent.com/web-app-rem.html) 2.http://www.w3cplus.com/css3/defin ...