DateTime add 1 day

后端 未结 2 757
眼角桃花
眼角桃花 2021-01-01 23:59

My Form has 2 fields - Time_from and Time_to

Now i need to add an entry in my database for each day (If theres is a difference between those days) ex. Time_from = 20

相关标签:
2条回答
  • 2021-01-02 00:10

    you can use Add function of Datatime object

    here i am giving you one example to add one 1 in your post date like

    <?php
    $date = new DateTime('2000-01-01');
    $date->add(new DateInterval('P1D'));
    echo $date->format('Y-m-d') . "\n";
    ?>
    

    OUTPUT

    2000-01-02
    

    Hope it will sure help you to solve your issue.

    0 讨论(0)
  • 2021-01-02 00:28
    $date = new DateTime('2017-01-17');
    $date->modify('+1 day');
    
    echo $date->format('Y-m-d'); // 2017-01-18
    

    You can do it too:

    $dateTo = new \DateTime('1980-12-07 +1 day');
    echo $dateTo->format('Y-m-d'); // 1980-12-08
    
    0 讨论(0)
提交回复
热议问题