两个日期之间的月份

两个日期之间的月份

Closed. This question needs details or clarity。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗?添加详细信息并通过editing this post阐明问题。
                        
                        6年前关闭。
                                                                                            
                
        
我想获取两个日期之间的月份列表,例如2013-04-01和2014-03-07
输出应该是这样的

month
April
may
june
.
.
.
March

最佳答案

我的建议是:

创建过程/功能

DELIMITER $$

USE `urlopy`$$

DROP PROCEDURE IF EXISTS `dowhile`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `dowhile`(dt_start DATE,dt_stop DATE)
BEGIN
  DECLARE v1 INT DEFAULT 0;

CREATE TEMPORARY TABLE tmp (
  `month_name` VARCHAR(256) DEFAULT NULL,
  `date_change` DATE DEFAULT NULL
) ENGINE=MYISAM DEFAULT CHARSET=utf8  ;


  SELECT TIMESTAMPDIFF(MONTH, dt_start, dt_stop)+1  INTO v1;
  WHILE v1 > -1 DO
    INSERT tmp (SELECT MONTHNAME( ADDDATE(dt_start, INTERVAL v1 MONTH) ),ADDDATE(dt_start, INTERVAL v1 MONTH) );
    SET v1 = v1 - 1;
  END WHILE;

SELECT * FROM tmp;
DROP TEMPORARY TABLE IF EXISTS tmp;

    END$$

DELIMITER ;


然后叫它

CALL dowhile('2012-05-05', '2013-06-04');

关于mysql - 如何获得两个日期之间的月份,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18735431/

10-11 08:02