Friday, May 11, 2012

In this blog i have come up with a solution to display the week , month , quarter,half, year of the dates in a range .
i have the following fields in my table 
date,week , month , qua,half,year
now , i have written the code for my store procedure , lets call it as daf(date function)
before getting into the coding part i would like to tell you that i am a novice in MySQL or php , but it took some jiffy time to learn all these slimy codes . k , coming back to the coding section ,oh! wait, let me describe the scenario first , the user gives two dates as input to the store procedure , and at the end he receives the out put as the   week , month , quarter,half, year of the dates in a range . k , here i copy paste the code ..
DELIMITER $$


DROP PROCEDURE IF EXISTS `daf` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `daf`(startdate date,enddate date)
BEGIN
declare week1,month1,half,qua,year1 varchar(50);


declare temp int;
declare date1,date2 date;
set date1=startdate;
set date2=enddate;
set temp=(SELECT DATEDIFF(date2,date1));


while temp>=0 do


set week1=(select week(date1));
set month1=(select month(date1));
set year1=(select year(date1));
set qua=(select quarter(date1));
if(qua>2)then
set half="2";
else
set half="1";
end if;
insert into dates (date1,week1,month1,half,qua,year1)values (date1,week1,month1,half,qua,year1);
set temp=(temp-1);
set date1=(select adddate(date1, INTERVAL 1 DAY));


end while;
select *from dates;
END $$


DELIMITER








calling the store procedure









output table




















hope u learnt how to display the week , month , quarter,half, year of the dates in a range .
thank you , c ya later with another intelligent coding >>>