Date in PHP CI

Source: Internet
Author: User
Cases:
Start time: 2014-10-01 15:13:35 end time: 2014-10-03 15:13:35

Requirements: When added, segments are based on days.
The fields displayed in the database are 3 paragraphs, one data for number 1th, one data for number 2nd, and one for number 3rd.

How to write?
Ask for answers, thank you.


Reply to discussion (solution)

$start _time = Strtotime ("2014-10-01 15:13:35"), $end _time  = Strtotime ("2014-10-03 15:13:35");//The following code presupposes the same month  If not the same year different months  plus the year and month judgement can be $days = date (' d ', $end _time)-date (' d ', $start _time) + 1;  3$data = Array (); for ($i = 0; $i < $days; $i + +) {    //Here you can add additional data for the corresponding date    $data [] [' date_time '] = Date (' y-m-d h:i : S ', $start _time + $i * 86400); }var_dump ($data);/* output is as follows: Array (    [0] = = Array        (            [date_time] = 2014-10-01 15:13:35        )    [1] =& Gt Array        (            [date_time] = 2014-10-02 15:13:35        )    [2] = = Array        (            [date_time] + = 2014-10-03 15:13:35        )) */

That's it

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.