I have two dates given, aug 27 2015 -> sep 9 2015. I'd like to know how much days have passed while using the UTC - 8 timezone. Can anyone share a small tutorial/code to help my case? Thank you so much.
Asked
Active
Viewed 34 times
-1
-
Stack Overflow is not a free code writing service. Show us your code and where you are stuck, then we are happy to help – Rizier123 Aug 29 '15 at 12:06
-
Okay, i'll update the post soon with my current code. – Jad Aug 29 '15 at 12:06
-
Please consider this: http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – Danny Aug 29 '15 at 12:07
-
Might I suggest searching for and reading about the DateTime object in PHP - it has a great many methods for dealing with dates, including periods of time between two dates – Professor Abronsius Aug 29 '15 at 12:07
2 Answers
2
You can use DateTime class also. And the DateTime.diff function.
<?php
$d1 = new DateTime();
$d1->setTimezone(new DateTimeZone('America/Los_Angeles')); //Do this for all 3 objects
$d2 = new DateTime();
$d3 = new DateTime();
$d1->setDate(2015, 8, 27);
$d2->setDate(2015, 9, 9);
$gone = $d1->diff($d3);
$left = $d2->diff($d3);
echo "<br>";
echo ($gone->format('%R%a days'))." gone. <br>";
echo ($left->format('%R%a days'))." left. <br>";
?>

bytestorm
- 1,411
- 3
- 20
- 36
1
After some research and reading some php documentation comments, this code worked for me:
<?php
date_default_timezone_set("America/Los_Angeles");
$date1 = strtotime("27 August 2015");
$days = floor((time() - $date1)/86400);
print("$days days have passed.\n");
?>

Jad
- 76
- 8