PHP - Time Remaining
I'm trying to make a code so that it will get the last date and timee it submitted into a database, but for this example I replaced the database loading with a default.
I am trying to make it so that it will deisplay how long you must wait until you can vote again, which is every 24hours. $diffrence = strtotime('2010-12-11 10:59:59') - time(); return ("". number_format(($diffrence / 60 / 60), 2) ." hours"); So, lets say the time now is "2010-12-11 20:59:59". 10 hours have passed, so now you have 14 more hours. Similar Tutorialsim using this code: PHP Code: [Select] Code: [Select] <?php set_time_limit(0); $file = 'test.mp3'; header('Content-Description: File Transfer'); header("Content-Disposition: attachment; filename=\"$file\""); header('Content-Type: audio-x/mp3'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($file)); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Expires: 0'); readfile($file); ?> when downloading i cant see the progress bar. thanks. Hello, Im making a little script to keep track on how much people have currently earnt on my site. I have everything work but i can't figure out how to work out the current balance At the moment ive got: Code: [Select] $currentbalance = $row['totalpaid'] - $row['points']; Which works untill the points becomes more then the total paid then it starts going in minus. Im sure there's a simple fix but i just can't think of a way. Any help would be great. Thanks hey guys thanks for the upcoming support how do I set the blue to fill up the remaining width of the while maininfo div? I tried setting the width:auto <div class="maininfo"> <div class="large">2</div> <div class="smallblock"> <div class="smalltop">3</div> <div class="small">4</div> </div> <div class="smallblock"> <div class="smalltop">5</div> <div class="small">6</div> </div> </div> .maininfo { width: 600px; } .large { float: left; height: 95px; background-color: blue; width:auto; } .smallblock { float: right; height: 90px; margin: 0 0 0 5px; width: 20%; } .small { background-color: red; height: 50%; width: 100%; } .smalltop { background-color: red; height: 50%; width: 100%; margin-bottom:5px; }Edit fiddle - JSFiddle I have to give credit to user "Psycho" here, who came up with the code I'm using for my Membership Directory. I have even completed all of the code that will allow companies to update their own information in the database when they need to. The last problem I'm having is with my "master" list of members. It is all working with the exception of - I can't get the County heading to show up when the actual County location in the database record is different from the last company. I get the heading properly on the first Company, but after that, even though I know the County data is changing, because I'm echoing out the data as it goes (for testing), and I'm just baffled - I have tried every placement of the IF conditional that I can think of. The current code results can be seen he http://www.nmlta.org..._list-test2.php
I'm sure there is a big clue because my flag that says "Checking County Match" is all occurring before the companies even print out, but I can't find the right change to make in my code, which follows:
// Retrieve ALL the "company" specific data (including contacts) $query = "SELECT company.*, co_contact.cont_name, co_contact.cont_title, co_contact.cont_email FROM company LEFT JOIN co_contact ON company.company_id = co_contact.company_id WHERE company.comp_type = 'Agent' ORDER BY company.comp_county, company.comp_name, co_contact.cont_rank"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); // Build the $company_array $company_array = array(); while($row = $result->fetch_assoc()) { if(!isset($company_array[$row['company_id']])) { //Add the company specific data here $company_array[$row['company_id']] = array( 'name' => $row['comp_name'], 'uw' => $row['comp_uw'], 'street' => $row['comp_street'], 'pobox' => $row['comp_pobox'], 'csz' => $row['comp_csz'], 'phone' => $row['comp_ph'], 'fax' => $row['comp_fx'], 'web' => $row['comp_web'], 'email' => $row['comp_email'], 'county' => $row['comp_county'], 'branches' => array(), 'br_contacts' => array() ); } //Add the company contact info here $company_array[$row['company_id']]['co_contacts'][] = array( 'name' => $row['cont_name'], 'title' => $row['cont_title'], 'email' => $row['cont_email'] ); } //Run query to get branch info - for ALL companies $query = "SELECT branch.*, br_contact.cont_name, br_contact.cont_title, br_contact.cont_email FROM branch JOIN company ON branch.company_id = company.company_id LEFT JOIN br_contact ON branch.branch_id = br_contact.branch_id WHERE company.comp_type = 'Agent' ORDER BY company.comp_county, branch.br_street, br_contact.cont_rank"; $result = $mysqli->query($query) or die($mysqli->error.__LINE__); //Add branch (and branch contacts) results to $company_array while($row = $result->fetch_assoc()) { $compID = $row['company_id']; $branchID = $row['branch_id']; if(!isset($company_array[$compID]['branches'][$row['branch_id']])) { $company_array[$compID]['branches'][$branchID] = array( 'branch_name' => $row['branch_name'], 'street' => $row['br_street'], 'csz' => $row['br_csz'], 'phone' => $row['br_ph'], 'fax' => $row['br_fx'] ); } $company_array[$compID]['branches'][$branchID]['br_contacts'][] = array( 'name' => $row['cont_name'], 'title' => $row['cont_title'], 'email' => $row['cont_email'] ); } echo "<span class='heading'>"; echo "2014-15 Agent Members of the New Mexico Land Title Association<br><br>"; echo "</span>"; $current_county = 'xxx'; // Start building the table for showing results echo "<table border='1' cellpadding='10' cellspacing='0' style='width:750px; margin-left:100px; margin-bottom:20px'>"; // Begin the "foreach" loop to check for County change foreach($company_array as $company) { echo "<font color='red'>Checking County Match</font><br>\n"; // Enter County IF Statement Here if ($company['county'] != $current_county) { echo "<tr><td><b><font class='county'>"; echo $company['county']," County</font><br><hr></b></td></tr>"; } // Begin the "foreach" loop for rows in the $company_array foreach($company_array as $company) { echo "<tr><td>\n"; $current_county = $company['county']; echo "This company is in $current_county County<br>\n"; echo "<b>{$company['name']}</b><br>\n"; if(!empty($company['uw'])) { echo "<b>{$company['uw']}</b><br>\n";} if(!empty($company['street'])) { echo "{$company['street']}<br>\n";} if(!empty($company['pobox'])) { echo "{$company['pobox']}<br>\n";} echo "{$company['csz']}<br>\n"; echo "{$company['phone']} Fax: {$company['fax']}<br>\n"; if(!empty($company['web'])) { echo "<a href='http://{$company['web']}' target='_blank'>{$company['web']}</a><br>\n";} if(!empty($company['email'])) { echo "Email: <a href='mailto:{$company['email']}'>{$company['email']}</a><br>\n";} // if(!empty($company['county'])) { // echo "Serving <font color='green'>{$company['county']} </font>County<br>\n";} echo "<br>"; foreach($company['co_contacts'] as $co_contact) { if(!empty($co_contact['name'])) { echo "    <b>{$co_contact['name']}</b>, {$co_contact['title']}<br>\n";} if(!empty($co_contact['email'])) { echo "    Email: <a href='mailto:{$co_contact['email']}'>{$co_contact['email']}</a><br>\n";} echo "<br>"; } foreach($company['branches'] as $branch) { echo "    <b>{$branch['branch_name']}</b><br>\n"; echo "    {$branch['street']}<br>\n"; echo "    {$branch['csz']}<br>\n"; echo "    {$branch['phone']} Fax: {$branch['fax']}><br>\n"; if(!empty($branch['email'])) { echo "    Email: <a href='mailto:{$branch['email']}'>{$branch['email']}</a><br>\n";} echo "<br>"; foreach($branch['br_contacts'] as $br_contact) { if(!empty($br_contact['name'])) { echo "        <b>{$br_contact['name']}</b>, {$br_contact['title']}<br>\n";} if(!empty($br_contact['email'])) { echo "        Email: <a href='mailto:{$br_contact['email']}'>{$br_contact['email']}</a><br>\n";} echo "<br>"; } } } echo "</td></tr>\n"; } echo "</table>"; ?>I will greatly appreciate someone pointing out my mistake, which I'm sure is obvious to code gurus - I am just baffled. Thanks! I Have field in my table with max length (10). My data is only (5) characters. ex: "apple" I want to output "apple ". with extra (5) space. Max Length: (10) - (5 characters: apple) = 5 extra white space to be added when outputting fruit. I know can echo it as $row['fruit'] . " "; < == manually, but I want it to be automated based on the number of "max_length" from my field in my table/database. PHP date and time function is not showing correct time on my local system I have the following php code date_default_timezone_set("Africa/Lagos"); $date = date('d-m-y h:i:s'); echo "Server Time ".$date ."<br>"; echo "The time is " . date("h:i:sa")."<br>"; $current_datetime = date("Y-m-d") . ' ' . date("H:i:s", STRTOTIME(date('h:i:sa'))); echo "Current time1: ".$current_datetime . "<br>";
Output
Server Time 21-05-21 09:55:39
Expected Output
Server Time 21-05-21 10:55:39
Any help would be appreciated. Edited May 21 by Ponel I am trying to simulate an ad expiration and carry out an action if the ad is expired. And I cannot get the if/else to work properly... I've tried many variations and I cannot see what I am doing wrong here. Any tips please 3 hours and counting of no solution! $ad_start = time()-14 . "<br />"; // 14 days from today in the past (negative) echo $ad_start; $current_time = time() . "<br />"; // current epoch time echo $current_time; $days_past = $ad_start - $current_time; // days past echo "<br />$days_past days have past since the ad started!<br />"; if($days_past <= 14) { echo "<br />Ad is less than 14 days. Not expired."; } else { echo "<br />Ad is over 14 days. Expired."; } Basically I have recently been playing around with parsing a csv file. What I am looking to do at this point is simply take the date/timestamp (part of the csv file), which is in the following format:DD/MM HH:MM:SS.100th/s For the sake of argument, lets say I have this in an array string called $csv[0] and the file has several lines that span the course of a couple hours. I wouldn't mind having to use explode() to breakup/remove the date or 100th/s IF that would make things a lot simpler. So where would I start in trying to achieve this?. The result I am looking for will simply return "X Seconds". Storing this in a string variable would be a bonus, as I plan to use this to divide a separate piece of information. Any examples or ideas would be great. Thank you. ps: Here is an example time from the csv file itself: Code: [Select] 11/19 22:23:18.143 PHP 5.2.6 We rent PHP server space on a server in California. Several of my pages generated by PHP show the current date and time, so when the page is printed, the user knows when the data was printed. Our users could be anywhere in the US, I am in Michigan. How do I convert the server time (PDT) into local time, regardless of where the user is? Thanks. Hello, I tried to implement some PHP code to enable a web page to show "Dinner" specials versus "Lunch" specials based on the time. The business is located in the Eastern Time Zone, so I only need to routine to work based on Eastern Time (New York). What I am noticing is that the server is processing the lines of code so fast that the command to establish the correct time for the remaining code is not always being acknowledged. This line of code appears to be processing too fast for the remaining lines of code: date_default_timezone_set ( "America/New_York" ); Is there some additional code I can put in place to make sure the correct time is always ascertained? I need the $hourmin variable to always return a combination of hour + minute based on 24-hour time and Eastern Time zone. My code is as follows: <?php $name8 = file_get_contents("test/special8name.txt"); date_default_timezone_set ( "America/New_York" ); $gethour = date("H"); $getminutes = $gettimedate["minutes"]; $gettimedate = date(); $hourmin = $gethour . $getminutes; $currentday = date("l", time()); $currentdate = date("M j, Y"); if ($hourmin < 1500 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesred\">$name8 </span>"; } else if ( $hourmin > 1500 && $hourmin < 2300 && $currentday <> "Saturday" && $currentday <> "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } else if ( $currentday == "Saturday" or $currentday == "Sunday") { echo "<span class=\"namesblue\">$name8 </span>"; } ?> This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 I am having a problem with PHP displaying the correct date and time. It updates as it should, but is fast by 4min and is always displaying a date in 2004. I ran a basic php script to make sure the application im using itself is not wrong. go to lunenburgledger.com/time.php Anybody had any ideas on where to check? The system time on the Windows Server 2003 is correct. The only thing I can think of is that it was converted to a virtual machine on vmware esxi, but the system time stayed right. Any ideas? Thanks! OK So I've got a datepicker that sends a date in d/m/y format. My DB stores the data in Unix Timestamp Which I can convert the date to with strtotime however this does the exact date & time. All I want is the actual day. I've spent hours trying to convert this with just the day with mixed results... Thanks.
What are the differences and implications of UTC time and Zulu time? <?php function getArr(string $time):array { $dateTime = new \DateTime($time); return [ 'time'=>$time, 'timestamp'=> $dateTime->getTimestamp(), 'dateTime' => $dateTime ]; } $arr = getArr('2020-08-05'); $arr_z = getArr('2020-08-05T00:00:00Z'); print_r($arr); print_r($arr_z); echo('equal timestamps: '.($arr['timestamp'] === $arr['timestamp']?'true':'false'));
Array ( [time] => 2020-08-05 [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 3 [timezone] => UTC ) ) Array ( [time] => 2020-08-05T00:00:00Z [timestamp] => 1596585600 [dateTime] => DateTime Object ( [date] => 2020-08-05 00:00:00.000000 [timezone_type] => 2 [timezone] => Z ) ) equal timestamps: true
I am making a time clock, and I was wondering what is the best way to calculate the number of hours an employee worked? I have a table called "statuses" it holds names of punch types: - id = the auto_inc - status = "in/out/break/lunch" text statuses - paid = whether or not the punch is paid or not (true/false) I have another table called "logging" This table holds the information about the punch type: - id = the auto_inc - owner = the member id - ip = members ip - inout = the punch type from the statuses table - location = the city/state of where the punch took place - date = the time the member punched Maybe I am over thinking this, but what is the best way to calculate the hours a person has worked? Right now I am getting all the punches for for a particular member between a date range. then loop through the data to display it and passing it to a method in a class called Calc. I want to then add the times from punch in to punch out, then the next punch in to punch out. Any suggestions? Let's say I am buying a share for $10. If I sell the share on the same day BEFORE 3:30PM, it will be sold for $10, but if I keep the share past 3:30PM, I want the code to automatically add $1 (Taxes and such) once in the the price of the share in database, after that no matter how many days pass by, the price will remain the same.
I've thought about CRON jobs, but I have no idea how to make/use them or set them up.
Any direction or help is appreciated.
I have this: $sql = mysqli_query($conn, "SELECT ip , page , CASE WHEN referrer = '' THEN 'N/A' ELSE referrer END as referrer , DATE_FORMAT(date, '%m/%d/%y') as date , TIME_FORMAT(time, '%T') as time FROM tblTraffic ORDER BY date DESC, time DESC"); most of my traffic report contains the correct times, my time, which is CST in the USA. but some records are off by a lot. Does the time() function capture the time of the actual location from which the visitor is coming from? if so, what could I do to return my timezone for any visitor? w3 schools and php.net don't mention this. Hi, The hosting provider for my domain confirm me that the server time is in EST (UTC-5). They also sent me a grab supporting that Code: [Select] server time is now: ---------------------- Sun Nov 7 02:20:01 EST 2010 ------------------- But when I use the following code, the output I get is has 1 hr difference (UTC-6) echo date("d M, Y h:i:s A",time()); Output==> 07 Nov, 2010 01:20:01 AM But it suppose to give the same time as the server, ryt? Can anybody please explain? Thanks, Hey Guys! I have the following doubt. When echoing from Server like this: Code: [Select] echo "time=" . time(); I get the time in the following raw format: 1299272294 I would really like to echo it with this format: Tue Mar 1 23:50:00 GMT-0300 2011 Is there a way I could do that? Really looking forward for some help on this one, Thanks a lot in advance! Cheers! Hey guys, How would I go about subtracting Today from a previous day to find the difference? For example, I want to subtract TODAY from a previous date in my database, to determine if the difference is greater than 1 day. Any ideas? I tried doing the subraction in TIMESTAMPS, but when I convert the date back to Y-m-d H:i:s, I got some weird year and time. |