search

Home  >  Q&A  >  body text

function - php dynamically get time range?

I want to implement a function. For example, if I want to get the time of the last 3 days, I will pass parameter 3 and return a string of 2017-06-18 - 2017-06-20. What should I do?

phpcn_u1582phpcn_u15822720 days ago711

reply all(2)I'll reply

  • 大家讲道理

    大家讲道理2017-06-21 10:13:21

    To dynamically obtain the time range, assign the n value of the last n days to $day

    <?php
        $day = 3;
        echo date("Y-m-d",strtotime("-".$day." days")).' - '.date("Y-m-d",time());
    ?>

    reply
    0
  • 滿天的星座

    滿天的星座2017-06-21 10:13:21

    echo date("Y-m-d",strtotime("-3 days")).' - '.date("Y-m-d",time());exit();

    reply
    0
  • Cancelreply