note 85917 modified in function.date by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Sep 2008 15:34:10 +0000 |
| Subject: | note 85917 modified in function.date by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-144674@lists.php.net to get a copy of this message | ||
I see a lot of solutions to date math / difference / subtraction issues, here's something I
found works and is much simpler than some of the other things here. Apparently converting date
values to a string allows you to apply arithmatic to them.
------------------------------
<?php
// Load the length of a song in seconds
$songLength = $emerge->getSongValue($sID, "songLength");
// Find when 1 frame started playing the song and convert that value to a string
// This works when pulling a datetime value from SQL
$songStart = (string)($emerge->getListItem("eID", $eID, "startTime"));
$songStart = (string)strtotime($songStart);
// The above is slightly roundabout, but seems to be the trick to getting PHP to stop treating
variables like date values and doing weird math.
// Find when the current frame was loaded.
// This works when just using PHP date/time values
$loadTime = (string)date("U");
// Calculate the difference in seconds and convert to a value for a refresh entry.
$timeDiff = $loadTime - $songStart;
$length = (($songLength - $timeDiff) * 1000);
?>
--was--
I see a lot of solutions to date math / difference / subtraction issues, here's something I
found works and is much simpler than some of the other things here. Apparently converting date
values to a string allows you to apply arithmatic to them.
------------------------------
// Load the length of a song in seconds
$songLength = $emerge->getSongValue($sID, "songLength");
// Find when 1 frame started playing the song and convert that value to a string
// This works when pulling a datetime value from SQL
$songStart = (string)($emerge->getListItem("eID", $eID, "startTime"));
$songStart = (string)strtotime($songStart);
// The above is slightly roundabout, but seems to be the trick to getting PHP to stop treating
variables like date values and doing weird math.
// Find when the current frame was loaded.
// This works when just using PHP date/time values
$loadTime = (string)date("U");
// Calculate the difference in seconds and convert to a value for a refresh entry.
$timeDiff = $loadTime - $songStart;
$length = (($songLength - $timeDiff) * 1000);
http://php.net/manual/en/function.date.php