note 85917 added to function.date

From: Date: Wed, 24 Sep 2008 15:28:39 +0000
Subject: note 85917 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-144673@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. ------------------------------ // 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); ---- Server IP: 66.207.199.35 Probable Submitter: 216.75.162.130 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/85917 Del: integrated -- https://master.php.net/note/delete/85917/integrated Del: useless -- https://master.php.net/note/delete/85917/useless Del: bad code -- https://master.php.net/note/delete/85917/bad+code Del: spam -- https://master.php.net/note/delete/85917/spam Del: non-english -- https://master.php.net/note/delete/85917/non-english Del: in docs -- https://master.php.net/note/delete/85917/in+docs Del: other reasons-- https://master.php.net/note/delete/85917 Reject -- https://master.php.net/note/reject/85917 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144673) next »