PHP - Displaying Minutes And Seconds Until Next Half Hour
Unfortunately I do not know how to go about doing this in php any simple examples of time and date will be great.
So what I am trying to do is, display to minutes until the next half hour as well as the seconds until the next minute. Eg. Code: [Select] <?php echo $minutes; ?>:<?php echo $seconds; ?> Any help using the time and or date functions in this case will be great. Thank you for your stupendous help. Brian Similar Tutorials
Hi, echo '<div style="float:right;width:60%;color:#666666">'. TeamSpeak3_Helper_Convert::version($ts3->virtualserver_uptime) .'</div>'; Edited June 24, 2020 by Lux05 Hi guys, I have a PHP Script were user would enter a username and password to get access, but the problem I keep having is every half n hour or so user have to sign in again cause the keeps logging them out for some reason. Please I need your help and advice to make this stop. Hey guys only thing i can find online is examples of showing how much time is left until a predetermind time. but what I need is how many minutes are left until the next hour hits anyone have any ideas on this? Im wanting to do it in UNIX time Other than if statement, is there a way to change a duration give in seconds (e.g. 5746 seconds) to the standard format of x hours and y minutes and z seconds? This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=352669.0 I wrote a function that grabs the elapsed time of a recently uploaded video. However, the time does not seem to increment. For example, if I upload a video, the time will display as '1 second'. However, if I continuously refresh the page, the time does not increment or increase. Any way to fix this? I figured I'd have to put it in some kind of loop (I do call the function in another class).
function getElapsedTime($time) { $time = time() - $time; // get time since video upload date $time = ($time < 1) ? 1 : $time; $tokens = array( 31536000 => 'year', 2592000 => 'month', 604800 => 'week', 86400 => 'day', 3600 => 'hour', 60 => 'minute', 1 => 'second' ); foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); return $numberOfUnits . ' ' . $text . (($numberOfUnits > 1) ? 's' : ''); } }
When I echo the current time, the hour is what it is plus one: echo date("h:i:s:A"); Real time is 3:46:33 Would display 4:46:33 What is wrong here? To get current date and time I use: $date = date("d-M-Y h:i:s"); But how can I get date and time which was before 5 minutes. I have a database with Users as a table. It has the normal stuff, id, username, password, and I have anther in it called lastactive. It is int(11) , and I am wondering how I would make a sql query select the users in the database 'users' and see who has been active in the past 15 mins. By the way, the lastactive time gets updated by the function time() Here is my code: <?php $online = mysql_query("SELECT * from users WHERE (TIMESTAMPDIFF(MINUTE, `lastactive`, NOW()) < 15) ORDER by lastactive DESC") or die (mysql_error()); while($online = mysql_fetch_assoc($online)) { echo '<a style="color:#F0CD87;" href="profile?id='.$online['user_id'].'">'; echo ucFirst($online['username']); echo '</a>, '; } ?> Here is how the last active gets updated. <?php if(isset($_SESSION['logged'])) { mysql_query("UPDATE `users` SET `lastactive`='" . time() . "' WHERE `username`='" . $_SESSION['username'] . "'"); } ?> Again its not showing the users that have been on since 15 minutes ago, even tho it updates the users last active on every page since its in the footer.php part. which is on every page. Thanks for the upcoming help. I'm trying to add some minutes ($interval) to any given time, but my results aren't as expected... Code: [Select] <?php $year="2012"; $opentime="09"; $interval="10"; $thedate = "$year:01:01 $opentime:00:00"; $startdate = strtotime($thedate); $date = date("Y-m-d",$startdate); $time = date("g:i a",$startdate); $newtime = strtotime("+$interval", $time); $nexttime = date("g:i a",$newtime); echo $date; echo "<br>"; echo $time; echo "<br>"; echo $nexttime; is returning: 2012-01-01 9:00 am 7:10 pm I was expecting the last to be 9:10 am. Can someone point me in the right direction? Thanks. Hi all,
Having an issue with some of my php code. The goal is to have two drop-down menus, one that pulls from "ahevents_scenarios". The second pulls the "sides" involved, however it does not go into dropdown. The other issue is that even though there are only 3 sides specified, all 5 show up on the webpage. This is in Joomla.
Here is my code...I think I've looked over this way too much and just can't find my errors anymore.
<?php if (! $my->id) { // shouldn't even get here since menu is viewable only through logged in status print "<b>Sorry, you must be registered and logged into this site to continue</b>\n"; } else { // include standard functions and db info require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/admin_functions.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/db_admin_functions.php"); // which scenario we doing? -- replace with table lookup in future opendb('ahevents_scenarios'); if(!isset($_POST['action'])) { // display form $sqlstr2 = "select id, name from scenarios order by name"; $result2 = mysql_query($sqlstr2) or die("Error: ".mysql_error()."<br>Query: $sqlstr2"); // display form ?> <form name="edit_reg" method="post" action="<? echo $_SERVER[ 'REQUEST_URI' ]; ?>" <table> <tr> <td>Select Scenario: </td> <td> <select name="id"> <? while ( $row = mysql_fetch_array($result2)) { printf("<option value=\"%s\">%s</option>\n",$row['id'], $row['name']); } ?> </td></tr> <tr> <td>Which Side?</td> <td><select name="side"> <option value="side_1">side_1</option> <option value="side_2" >side_2</option> <option value="side_3" >side_3</option> <option value="all" selected>All</option> </select> </td></tr> </table> <p> <input type="submit" name="action" value="Get Registrants"> <input type="reset" value="Reset"> <input type="button" name="" value="Back" onClick="history.back()"> </form>The goal is to download the registrants into a .csv file, which it does, however due to not being able to select a "side", the .csv is blank with only headers, no content. Thanks for your time Rob hello, if i have the following, how would i display it? Code: [Select] function minutes_round ($hour = "$signintime", $minutes = '5', $format = "H:i") { $seconds = strtotime($hour); $rounded = round($seconds / ($minutes * 60)) * ($minutes * 60); return date($format, $rounded); } I have a forum script I made that has thread bumping for the thread creator only. I am trying to limit the amout of time the creator can bump to be every 10 minutes. Here's my code. list($title, $creator, $locked, $hidden, $moved, $lastbump) = mysql_fetch_row(mysql_query('SELECT title, creator, locked, hidden, moved, lastbump FROM forum_threads WHERE id="'.$_GET['threadid'].'"')); if(($locked == 1 || $hidden == 1 || $moved == 1) && !$_SESSION['rights'] == 2){ header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } else { if($creator == $_SESSION['username']){ mysql_query("UPDATE forum_threads SET lastbump = NOW() WHERE id='".$_GET['threadid']."'"); } else { header("location: thread.ws?id=".$_GET['threadid']."&page=".$_GET['page'].""); } } so i have a mysql column with a datetime and i was wondering how i could make it echo the time in "X minutes ago" or "X hours ago" and also, when its more then 24 hours old, delete the entire entry I've created a demo page for my CMS, and I want to delete itself and make a fresh content install. I got the delete part figured out, but what about uploading fresh content files? (only a few text files). Here's the delete part: Code: [Select] <?php $expiretime=720; // minutes (in how many minutes it deletes the files) $tmpFolder="tmp/"; // where to delete the files - be careful with this. $fileTypes="*.*"; foreach (glob($tmpFolder . $fileTypes) as $Filename) { $FileCreationTime = filectime($Filename); $FileAge = time() - $FileCreationTime; if ($FileAge > ($expiretime * 60)){ //deleting files: unlink($Filename); } } ?> Hi guys, So here is the deal. We have a list of brands that excists in a database. There are also images associated with the names. But not all the brands have images. So in the script i read if the file excists. Well this all works fine but it looks horrible. So i want to break the list in half (or limit it to 24). But i cant limit the sql query. Is there a way to "limit" a while loop and let it resume on the same page, just to change the layout (multiple collumns)? (I hope i am clear on this... i confuse even myself) $host = 'localhost'; $user = 'qwerty'; $pass = 'qwerty'; $db = 'qwerty'; $query = "SELECT * FROM ros_brands"; $result = mysql_query($query) or die(mysql_error()); $filename = "/resources/images/mm_files/" . $row['image_file_id'] . ".gif"; while($row = mysql_fetch_array($result)){ $filename = "/var/www/vhosts/test.nl/httpdocs/resources/images/mm_files/" . $row['image_file_id'] . ".gif"; if (file_exists($filename)) { echo "<a href='#'><img src='/resources/images/mm_files/" . $row['image_file_id'] . ".gif' /><span>". $row['name'] ."</span></a>"; } else { // echo "The file $filename does not exist"; } } I am just helping out a friend with his online store that he would like to add multiple currencies to. I made this script to help him out: $price = 99.95; $default_currency = 20; // displays all the file nodes if(!$xml=simplexml_load_file('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml')){ trigger_error('Error reading XML file',E_USER_ERROR); } else { $array['currency'][1] = 'EUR'; $array['value'][1] = 1.00; $i = 2; foreach ($xml->Cube->Cube->children() as $node) { $arr = $node->attributes(); // returns an array $array['currency'][$i] = $arr['currency']; $array['value'][$i] = $arr['rate']; $i++; } } if (isset($_POST['currency'])){ $currency = $_POST['currency']; } else { $currency = $default_currency; } $price = $array['value'][$currency] / $array['value'][$default_currency] * $price; $price = round($price, 2); $currency_name = $array['currency'][$currency]; echo '<p>Price is '.$currency_name.$price.'<br /> To change currency, select from dropdown box below.</p>'; echo '<form action="currency.php" method="post"><select name="currency">'; $i = 1; foreach ($array['currency'] as $value){ echo '<option value="'.$i.'">'.$value.'</option>'; $i++; } echo '</select><br /><input type="submit" /></form><br />'; $i = 1; foreach ($array['currency'] as $value){ echo '<p>'.$value.' = '.$array['value'][$i].'</p>'; $i++; } But for some reason it only works some of the time and I can't work out why for the life of me. If I could get some help in the matter, that would be greatly appreciated. A link to the above example can be found here. Regards, I. $time="19:00:00"; how to do i output one hour later from the variable above? Hi, i'm trying to create some detailed statistics about customer activity, i have entries in my mysql db when the customer has been active for the last time and want to create some statistics about that, basically a "online last 24 hours" but from specific countries. Now i've tried this: Code: [Select] $time = date('Y-m-d H:i:s'); $time24 = date("Y-m-d H:i:s", time()-((60*60)*24)); $query = "SELECT COUNT(*) as Anzahl FROM customers WHERE country = 'de' AND time BETWEEN '$time' AND '$time24' "; to get the current date and select all customers that have been available from the current date minus 24 hours, what's my mistake here, as this doesn't seem to work! Thanks I am trying to display date and time below code display date correctly but when it come to display time it display 3 hour behind. eg. when it is 12:47 PM in my system it display 9:47 PM Code: [Select] <?php $todaydate=date("j - F - Y g:i:s a"); echo $todaydate; ?> |