jquery教程

推荐列表 站点导航

当前位置:首页 > jquery > jquery教程 >

mysql日期转换和数字格式转换实例

来源:网络整理  作者:  发布时间:2020-12-20 20:30
mysql日期转换和数字格式转换实例...

//时间转成年月日时分秒
如select left(concat('00'),@num),3)就会显示三位数字的字符串,@num=1时显示001,为123是显示123。
select DATE_ADD(now(), Interval -1 year)
select date_sub(date_sub(date_format(now(),'%Y%m%d'),interval extract(day from now()) day),interval 0 month);

//上个月第一天和最后一天
//第几周
在mysql中,没有类似oracle的to_char(num,format)函数,所以涉及到数字前面补0的情况需要特殊处理。
//昨天此时
select weekofyear('20090606')

select date_format(DATE_ADD('20090605123020', Interval 20 minute),'%Y%m%d')
select DATE_ADD(now(), Interval -1 second)
//一秒钟前
//时间转成年月日
select DATE_ADD(now(), Interval -1 minute)
select date_sub(date_sub(date_format(now(),'%Y%m%d'),interval extract( day from now())-1 day),interval 1 month);

在mysql中,会把'20090707123050'和'20090707'格式的字符串作为date类型转换。
select weekofyear( now() )
select date_format(now(),'%Y%m%d%H%i%S')
//一小时前
 
//某个字符串
select DATE_ADD(now(), Interval -1 day)
select date_format(DATE_ADD(now(), Interval 1 day),'%Y%m%d')

select date_format(now(),'%Y%m%d')
select DATE_ADD(now(), Interval -1 month)
//去年此时
//上月此时
CONCAT(YEAR(a.createtime),LEFT(CONCAT('0',WEEKOFYEAR(a.createtime)),2))

select DATE_ADD(now(), Interval -1 hour)
//一分钟前
//昨天(年月日)

相关热词: MYSQL 实例

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jq/jc/6266.shtml

相关文章
最新文章
PHP识别相片是否是颠倒的 PHP识别相片是否是颠倒的

时间:2020-12-28

python编程有哪些ide python编程有哪些ide

时间:2020-12-28

python开发工程师是做什么 python开发工程师是做什么

时间:2020-12-28

php构造函数的作用 php构造函数的作用

时间:2020-12-28

php怎么跟数据库连接 php怎么跟数据库连接

时间:2020-12-28

php实现顺序线性表 php实现顺序线性表

时间:2020-12-28

Python多重继承中的菱形继 Python多重继承中的菱形继

时间:2020-12-28

php中break的作用 php中break的作用

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

mysql日期转换和数字格式转换实例

2020-12-20 编辑:

//时间转成年月日时分秒
如select left(concat('00'),@num),3)就会显示三位数字的字符串,@num=1时显示001,为123是显示123。
select DATE_ADD(now(), Interval -1 year)
select date_sub(date_sub(date_format(now(),'%Y%m%d'),interval extract(day from now()) day),interval 0 month);

//上个月第一天和最后一天
//第几周
在mysql中,没有类似oracle的to_char(num,format)函数,所以涉及到数字前面补0的情况需要特殊处理。
//昨天此时
select weekofyear('20090606')

select date_format(DATE_ADD('20090605123020', Interval 20 minute),'%Y%m%d')
select DATE_ADD(now(), Interval -1 second)
//一秒钟前
//时间转成年月日
select DATE_ADD(now(), Interval -1 minute)
select date_sub(date_sub(date_format(now(),'%Y%m%d'),interval extract( day from now())-1 day),interval 1 month);

在mysql中,会把'20090707123050'和'20090707'格式的字符串作为date类型转换。
select weekofyear( now() )
select date_format(now(),'%Y%m%d%H%i%S')
//一小时前
 
//某个字符串
select DATE_ADD(now(), Interval -1 day)
select date_format(DATE_ADD(now(), Interval 1 day),'%Y%m%d')

select date_format(now(),'%Y%m%d')
select DATE_ADD(now(), Interval -1 month)
//去年此时
//上月此时
CONCAT(YEAR(a.createtime),LEFT(CONCAT('0',WEEKOFYEAR(a.createtime)),2))

select DATE_ADD(now(), Interval -1 hour)
//一分钟前
//昨天(年月日)

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jq/jc/6266.shtml

相关文章

风云图片

推荐阅读

返回jquery教程频道首页