[分享]刚学mysql,写了一个反回两日期的相差分钟数的函数
刚刚看到有人提问这问题.这写了一下.谁知道.写完.帖就被人删了.
只好帖出来.分享一下.
delimiter $$
drop function if exists minuteDiff $$
create function minuteDiff(start_date datetime,end_date datetime)
returns integer
begin
declare m integer;
declare next_date datetime;
set m=0;
set next_date=start_date+interval 1 minute;
while next_date <=end_date do
set m=m+1;
set next_date=next_date+interval 1 minute;
end while;
return m;
end $$
delimiter ;
调用:
select minuteDiff( '2007-08-27 10:10:00 ', '2007-08-27 12:10:00 ') as diffMinute;
------解决方案--------------------select datediff(now(),date_sub(now(),interval 1 day))*24*60;
------解决方案--------------------呵呵,分享分享