How to display hours between two dates in mysql
Two datefield
<input type="text" name="from date" >
<input type="text" name="to date" >
E开发者_StackOverflow中文版xample : If fromdate is 2011-09-12
and todate is 2011-09-15
ouput should display :
display every hour
2011-09-12 00:00:00
2011-09-12 01:00:00
2011-09-12 02:00:00
2011-09-12 03:00:00
2011-09-12 04:00:00
.
.
.
.
.
2011-09-15 23:00:00
it is possible in mysql code or php
Try this:
<?php
$from_date_time = strtotime($_POST['from_date']);
$to_date_time = strtotime($_POST['to_date']);
while ($from_date_time < $to_date_time) {
echo date('Y-m-d H:i:s', $from_date_time);
$from_date_time += 3600;
}
hello in MS SQL server 2005 you can do this by the following code of using CTE..
declare @dateh table(ind int identity(1,1),date1 smalldatetime,date2 smalldatetime)
insert into @dateh select '1/1/2011','1/2/2011'
select * from @dateh
;with T as
(
select date1,date2 from @dateh as d
union all
select dateadd(hh,1,date1),date2 From T
where dateadd(hh,1,date1)<= date2
)
Select date1 from T
精彩评论