Find amount of days between 2 dates in php

后端 未结 2 1361
忘掉有多难
忘掉有多难 2020-12-22 08:46

I have 2 dates and want to know how many the amount of days that come between them.

Lets say these two are the dates

2015-11-16 10:01:13

2条回答
  •  粉色の甜心
    2020-12-22 09:03

    Following my comment, I thought I would post some examples from the PHP.net manual:

    OOP style:

    diff($datetime2);
    echo $interval->format('%R%a days');
    ?>
    

    Procedural style:

    format('%R%a days');
    ?>
    

    Both examples will output:

    +2 days

    You can also compare word strings as such (when using OOP style, this is an example from PHP.net):

     $date2);
    ?>
    

    Producing:

    bool(false)
    bool(true)
    bool(false)

    Using your dates:

    OOP

    diff($datetime2);
    echo $interval->format('%R%a days');
    ?>
    

    Procedural

    format('%R%a days');
    ?>
    

    Result from both:

    -194 days

    I sincerely hope this helps :)

提交回复
热议问题