MySQL 获取当前时间的30天所有日期

第一种:

sql:

select date_add(curdate(), interval(cast(help_topic_id as signed) - 29) day) as aday
from mysql.help_topic
where help_topic_id < 30
order by help_topic_id

 结果:

MySQL 获取当前时间的30天所有日期_第1张图片

 第二种:

SELECT DATE_FORMAT( DATE_SUB( DATE_SUB(curdate(),INTERVAL -1 DAY), INTERVAL ac DAY ), '%Y-%m-%d' ) AS endTime FROM 
( 
	SELECT @ai := @ai+1 AS ac FROM 
		( SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 ) ac1, 
		( SELECT 1 UNION SELECT 2 UNION SELECT 3 UNION SELECT 4 UNION SELECT 5 UNION SELECT 6 ) ac2, 
		( SELECT @ai := 0 ) xc0 
) ad where 1=1 ORDER BY endTime asc

sql:

 结果:

MySQL 获取当前时间的30天所有日期_第2张图片

 版权声明:本文为CSDN博主「谁喝了我的幽兰拿铁」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:

https://blog.csdn.net/yaoyulan21/article/details/122124061

MySQL 获取当前时间的30天所有日期_yaoyulan21的博客-CSDN博客第一种:sql:select date_add(curdate(), interval(cast(help_topic_id as signed) - 29) day) as adayfrom mysql.help_topicwhere help_topic_id < 30order by help_topic_id结果:第二种:SELECT DATE_FORMAT( DATE_SUB( DATE_SUB(curdate(),INTERVAL -1 DAY),..https://blog.csdn.net/yaoyulan21/article/details/122124061

你可能感兴趣的:(mysql,数据库,database,sql)