Last active
February 18, 2021 21:17
-
-
Save UVLabs/b98047abd622caa9380e713bd8249343 to your computer and use it in GitHub Desktop.
Get the number of days since a specific date or timestamp in PHP with timezone support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$date_in_the_past = '@1613681176'; // If using timestamps be sure to include '@' symbol | |
$date_in_the_past_obj = new DateTime($date_in_the_past); | |
// If timezones matter for your usecase, then use below instead. Ref: https://www.php.net/manual/en/timezones.php | |
// $date_to_check = '2021-02-18'; | |
// $date_to_check_obj = new DateTime($date_to_check, new DateTimeZone('America/St_Lucia')); | |
// You can add a different date that you want to compare instead of "today" | |
$date_in_the_future = new DateTime('today'); | |
$date_difference = $date_in_the_past_obj->diff($date_in_the_future); | |
$days_since = (int) $date_difference->format('%a'); | |
echo $days_since; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment