note 124554 added to class.datetime
| From: | ivijan dot stefan at gmail dot com | Date: | Tue, 31 Dec 2019 08:03:57 +0000 |
| Subject: | note 124554 added to class.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-213715@lists.php.net to get a copy of this message | ||
Here is easiest way to find the days difference between two dates:
<?php
if(!function_exists('date_between')) :
function date_between($date_start, $date_end)
{
if(!$date_start || !$date_end) return 0;
if( class_exists('DateTime') )
{
$date_start = new DateTime( $date_start );
$date_end = new DateTime( $date_end );
return $date_end->diff($date_start)->format('%a');
}
else
{
return abs( round( ( strtotime($date_start) - strtotime($date_end) ) / 86400 ) );
}
}
endif;
?>
In the general, I use 'DateTime' to find days between 2 dates. But if in the some reason,
some server setup not have 'DateTime' enabled, it will use simple (but not safe)
calculation with 'strtotime()'.
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.167.36 (proxied: 217.138.192.44)
----
Manual Page -- http://php.net/manual/en/class.datetime.php
Edit -- https://master.php.net/note/edit/124554
Del: integrated -- https://master.php.net/note/delete/124554/integrated
Del: useless -- https://master.php.net/note/delete/124554/useless
Del: bad code -- https://master.php.net/note/delete/124554/bad+code
Del: spam -- https://master.php.net/note/delete/124554/spam
Del: non-english -- https://master.php.net/note/delete/124554/non-english
Del: in docs -- https://master.php.net/note/delete/124554/in+docs
Del: other reasons-- https://master.php.net/note/delete/124554
Reject -- https://master.php.net/note/reject/124554
Search -- https://master.php.net/manage/user-notes.php