将具体日期计为一个1字

时间:2016-12-31 11:14:59

标签: php

我有很多约会。格式如下:

begin      
declare @h int ,@m int ,@tm int , @min int , @count int ,@d varchar(30)
       ,@dt datetime , @d1 varchar(30) , @dt2 datetime , @dt1 datetime

select @dt  = convert(datetime,(dateadd(day,-90,getdate())),105)    
select @d   = convert(varchar,@dt,105) 
select @dt1 = convert(datetime,getdate(),105)
select @d1  = convert(varchar,@dt1,105)
select @dt2 = convert(datetime,@d1,105)

select trainer 
     , sum(DATEPART(hh,(convert(datetime,hrs,1))))    
       + sum(DATEPART(mi,(convert(datetime,hrs,1)))) / 60 AS [Hour]
FROM sonvininsert 
where date  between convert(datetime,@d,105) 
                and convert(datetime,@d1,105)      
and instructore='primary' 
and status='0' 
group by trainer     

end 

我希望结果是这样的:

August 28, 2016 at 09:20AM
August 28, 2016 at 09:20AM
August 28, 2016 at 09:26AM
August 28, 2016 at 09:26AM
August 28, 2016 at 09:26AM

每一行都与新行分开(输入键盘)。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:0)

将它放入数组并执行此操作:

array_keys(array_count_values($array));

PHP代码

<?php
    $s = 'August 28, 2016 at 09:20AM
August 28, 2016 at 09:20AM
August 28, 2016 at 09:26AM
August 28, 2016 at 09:26AM
August 28, 2016 at 09:26AM';
    $s = explode(PHP_EOL, $s);
    $s = array_count_values($s);
    var_dump($s);
    print_r($s);
?>

<强>输出

array(2) {
  ["August 28, 2016 at 09:20AM"]=>
  int(2)
  ["August 28, 2016 at 09:26AM"]=>
  int(3)
}
Array
(
    [August 28, 2016 at 09:20AM] => 2
    [August 28, 2016 at 09:26AM] => 3
)