创建mysql日期范围 [英] Create mysql date range

查看:106
本文介绍了创建mysql日期范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎找不到我正在寻找的答案。

Can't seem to find the answer I am looking for.

我想创建一系列的日期从2010-11-01到2015-01- 01在表中。

I want to create a range of dates from 2010-11-01 to 2015-01-01 in a table.

2010-11-01
2010-11-02
2010-11-03
etc .. 。

2010-11-01 2010-11-02 2010-11-03 etc...

列数据类型为'Date'

Column datatype is 'Date'

感谢

推荐答案

DROP PROCEDURE IF EXISTS datespopulate;
DELIMITER |
CREATE PROCEDURE datespopulate(dateStart DATE, dateEnd DATE)
BEGIN
  WHILE dateStart <= dateEnd DO
    INSERT INTO datetable (d) VALUES (dateStart);
    SET dateStart = date_add(dateStart, INTERVAL 1 DAY);
  END WHILE;
END;
|
DELIMITER ;
CALL datespopulate('2010-11-01','2015-01-01');

注意我命名我的表 datetable 并且列被命名为 d ,但是随意更改此。在我的尽头工作正常,让我知道,如果你遇到一个问题。

Note I named my table "datetable" and the column is named "d", but feel free to change this. Works fine on my end, let me know if you run in to an issue.

为了让球滚动,对乔而言。 ; - )

Kudos to Joe for getting the ball rolling. ;-)

这篇关于创建mysql日期范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆