Home >Backend Development >PHP Tutorial >php CI 中的日期

php CI 中的日期

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-23 13:10:011238browse

例:
      开始时间:2014-10-01 15:13:35      结束时间:2014-10-03 15:13:35

要求:添加时,根据天来分段。
          在数据库中显示的字段为3段,   1号的一条数据,2号的一条数据,3号的一条数据。

 怎么编写?
 求解答,谢谢。


回复讨论(解决方案)

$start_time = strtotime("2014-10-01 15:13:35");$end_time  = strtotime("2014-10-03 15:13:35"); // 以下代码前提是同年同月  如果不同年不同月  加上年份和月份判断即可$days = date('d',$end_time) - date('d',$start_time) + 1;  // 3$data = array();for( $i = 0; $i < $days; $i++ ) {    // 此处可以添加对应日期的其他数据    $data[]['date_time'] = date('Y-m-d H:i:s', $start_time + $i * 86400 ); }var_dump( $data );/* 输出如下:Array(    [0] => Array        (            [date_time] => 2014-10-01 15:13:35        )    [1] => Array        (            [date_time] => 2014-10-02 15:13:35        )    [2] => Array        (            [date_time] => 2014-10-03 15:13:35        ))*/

就是这样

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn