MySQL时间函数from_unixtime()date_format()unix_timestamp()now()使用说明

now() 当前时间
mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2018-09-10 19:20:19 |
+---------------------+
1
2
3
4
5
6
unix_timestamp() 当前时间戳
mysql> select unix_timestamp();
+------------------+
| unix_timestamp() |
+------------------+
| 1536578429 |
+------------------+
1
2
3
4
5
6
unix_timestamp(now()) 当前时间转换成时间戳
mysql> select unix_timestamp(now());
+-----------------------+
| unix_timestamp(now()) |
+-----------------------+
| 1536578445 |
+-----------------------+
1
2
3
4
5
6
unix_timestamp(‘2018-08-08’) 指定时间转换成时间戳
mysql> select unix_timestamp(‘2018-08-08‘);
+------------------------------+
| unix_timestamp(‘2018-08-08‘) |
+------------------------------+
| 1533657600 |
+------------------------------+
1
2
3
4
5
6
from_unixtime(1533657600) 将时间戳转换为时间 默认格式 ‘%Y-%m-%d %H:%i:%s’
mysql> select from_unixtime(1533657600);
+---------------------------+
| from_unixtime(1533657600) |
+---------------------------+
| 2018-08-08 00:00:00 |
+---------------------------+
1
2
3
4
5
6
from_unixtime(1533657600, ‘%Y-%m-%d’) 将时间戳转换为时间 并进行格式化
mysql> select from_unixtime(1533657600, ‘%Y-%m-%d‘);
+---------------------------------------+
| from_unixtime(1533657600, ‘%Y-%m-%d‘) |
+---------------------------------------+
| 2018-08-08 |
+---------------------------------------+
1
2
3
4
5
6
查询时间戳字段 转换为时间格式显示
mysql> select from_unixtime(ctime, ‘%Y-%m-%d‘) from logs limit 1;
+----------------------------------+
| from_unixtime(ctime, ‘%Y-%m-%d‘) |
+----------------------------------+
| 2018-09-18 |
+----------------------------------+
1
2
3
4
5
6
where时间戳字段
mysql> select count(*) from logs where from_unixtime(ctime, ‘%Y%m%d‘)=20180808 limit 1;
+----------+
| count(*) |
+----------+
| 12345 |
+----------+
1
2
3
4
5
6
date_format() 将时间进行格式化显示
mysql> select date_format(now(), ‘%Y/%m/%d‘);
+--------------------------------+
| date_format(now(), ‘%Y/%m/%d‘) |
+--------------------------------+
| 2018/08/08 |
+--------------------------------+
1
2
3
4
5
6
where时间字段
mysql> select count(*) from logs where date_format(cdate, ‘%Y%m%d‘)=20180910 limit 1;
+----------+
| count(*) |
+----------+
| 123 |
+----------+
————————————————
版权声明:本文为CSDN博主「gocuber」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/gocuber/article/details/80195591

原文地址:https://www.cnblogs.com/apolloren/p/12106496.html

时间: 2024-08-04 00:23:05

MySQL时间函数from_unixtime()date_format()unix_timestamp()now()使用说明的相关文章

mysql 时间函数实战

mysql 时间函数实战 MySQL日期数据类型.MySQL时间类型使用总结,需要的朋友可以参考下. MySQL 日期类型:日期格式.所占存储空间.日期范围 比较. 日期类型 存储空间       日期格式                 日期范围 ------------ ---------   ---------------------    ----------------------------------------- datetime         8 bytes   YYYY-M

mysql时间函数,总是记不住,总是查。

http://www.cnblogs.com/zeroone/archive/2010/05/05/1727659.html UNIX_TIMESTAMP() UNIX_TIMESTAMP(date) 返回一个Unix时间戳(从'1970-01-01 00:00:00'GMT开始的秒数,date默认值为当前时间)mysql> select UNIX_TIMESTAMP(); -> 882226357 mysql> select UNIX_TIMESTAMP('1997-10-04 22:

mysql 时间函数date_format

http://toptree.iteye.com/blog/812642今天,在开发邮件系统的时候发现有很多的邮件没有发送成功,想手动把数据修改.找了mysql 的日期函数 获得的pubtime为String型,在sql语句中用mysql的时间函数date_format('time','format')转换: String sqlstr="select * from do_document where pub_time<date_format('"+pubtime+"'

MySQL时间函数

1. MySQL 为日期增加一个时间间隔:date_add() set @dt = now(); select date_add(@dt, interval 1 day); - 加1天 select date_add(@dt, interval 1 hour); -加1小时 select date_add(@dt, interval 1 minute); - 加1分钟 select date_add(@dt, interval 1 second); -加1秒 select date_add(@d

mysql时间函数操作

Mysql时间转换函数 https://blog.csdn.net/w_qqqqq/article/details/88863269 https://blog.csdn.net/w_qqqqq/article/details/88863269 mysql时间日期函数 https://www.cnblogs.com/weibanggang/p/9574987.html mysql获取当前时间,前一天,后一天 https://blog.csdn.net/csdn_ds/article/details

mysql 时间函数转换

1 NOW() //当前时间 2 SYSDATE() //当前时间 3 CURRENT_TIMESTAMP 4 以'YYYY-MM-DD HH:MM:SS'或YYYYMMDDHHMMSS格式返回当前的日期和时间,取决于函数是在一个字符串还是在数字的上下文被使用. 5 mysql> select NOW(); 6 -> '1997-12-15 23:50:26' 7 mysql> select NOW() + 0; 8 -> 19971215235026 1 UNIX_TIMESTA

MySQL时间函数-获取当前时间-时间差

MySQL中获取当前时间为now(),不同于sqlserver getdate(). SQLServer转MySQL除变化top 1 -> limit 1之后报错: select 1 from record_visitor where visitor_ip='' and datediff(mi,visitor_time,getdate())<=30 limit 1 [Err] 1582 - Incorrect parameter count in the call to native func

mysql 时间函数

SELECT * FROM `tbl` where `endTime`>NOW(); //now() SELECT NOW(),CURDATE(),CURTIME(); now():YYYY-MM--DD HH:MM:SS curdate():YYYY-MM--DD curtime():HH:MM:SS http://www.w3school.com.cn/sql/func_now.asp

MySQL单行函数

1.CONCAT(str1,str2,...) 返回来自于参数连结的字符串.如果任何参数是NULL,返回NULL.可以有超过2个的参数.一个数字参数被变换为等价的字符串形式.  select CONCAT('My', 'S', 'QL');--'MySQL'  select CONCAT('My', NULL, 'QL'); -> NULL 2. LENGTH(str) 返回字符串str的长度.    select LENGTH('text'); -> 4 3 .LOCATE(substr,s