时间维度填充问题
我的 MySql 表返回的是天而不是时间。我每天需要最少的分钟数,因此应该自动填充 1440 条记录,但我不断地返回几天。知道为什么吗?另外,我不需要秒,只需要小时和分钟,但我不确定如何在没有秒的情况下填充日期,因为时间格式始终为“00:00:00”
程序如下:
DELIMITER //
CREATE PROCEDURE p_sc_time(IN startdate DATETIME,IN stopdate DATETIME)
BEGIN
DECLARE currentdate DATE;
SET currentdate = startdate;
WHILE currentdate < stopdate DO
INSERT INTO sc_time VALUES (
NULL,
TIME(currentdate),
HOUR(currentdate),
MINUTE(currentdate));
SET currentdate == ADDDATE(currentdate,INTERVAL 1 MINUTE);
END WHILE;
END
//
DELIMITER ;
TRUNCATE TABLE sc_time;
CALL p_sc_time('01-01-01 00:00:00','01-01-01 23:59:59');
My MySql table is returning days instead of time. I need a minimum level of minutes in a day so 1440 records should be auto populated but i keep getting days back. Any idea why? Also i dont need seconds, only hours and minutes but i am not sure how to do a date fill without seconds since the format of time is always '00:00:00'
The procedure is below:
DELIMITER //
CREATE PROCEDURE p_sc_time(IN startdate DATETIME,IN stopdate DATETIME)
BEGIN
DECLARE currentdate DATE;
SET currentdate = startdate;
WHILE currentdate < stopdate DO
INSERT INTO sc_time VALUES (
NULL,
TIME(currentdate),
HOUR(currentdate),
MINUTE(currentdate));
SET currentdate == ADDDATE(currentdate,INTERVAL 1 MINUTE);
END WHILE;
END
//
DELIMITER ;
TRUNCATE TABLE sc_time;
CALL p_sc_time('01-01-01 00:00:00','01-01-01 23:59:59');
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有正在运行的 MySQL 实例来测试,但我相信您应该将当前日期类型更改为 DATETIME。
I don't have a running instance of MySQL to test, but I believe you should change your currentdate type to DATETIME.