note 85917 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 26 Oct 2008 12:57:59 +0000 |
| Subject: | note 85917 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-145765@lists.php.net to get a copy of this message | ||
Note Submitter: dave dot artur at gmail dot com
----
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);
?>