PHP - Time Limit
Hi,
I'm fairly new to all of this and I'm not quite sure what to do. I'm trying to create a field in my database that's 4 hours and 10 minutes into the future from the current time. What data type do I set my field as in the mysql database? How would I populate that mysql field via php.. would I use something like NOW(), or use the php date() function? Also, how would I be able to tell if my field has "expired" (the 4 hours and 10 minutes has elapsed)? Similar TutorialsHi, I have a timestamp mysql field that I'm trying to see if something happened within a time limit. The field is updated with the time when the action is complete so I just need to figure out how to see if it's within a time. I currently have a defined variable set titled "MAX_RESPONSE_TIME" and that's in seconds. By default "MAX_RESPONSE_TIME" is equal to 300 seconds. How can I see if a mysql timestamp field is within 300 seconds? Hello, I need to interrupt the execution of an oracle query if it is taking more than 10 seconds, and give user a message informing him about execution timeout. I googled a lot but i didn't find anything useful. Is there any way to set a time limit to oci_execute. I cannot modify DB settings... Any Idea? Thnks can we set limit in safe mode as the hosting company would not off the safe mode so please help i get following error, Warning: set_time_limit() [function.set-time-limit]: Cannot set time limit in safe mode in /home/evercash/public_html/5dollarmatrix.co.cc/admin.php on line 190 elseif($b=="Compress Matrix") { set_time_limit(6000); include "config.php"; Unless buffer overflows or breaking out of code to perform a new command are problems that have been solved.... I am trying to figure out the proper PHP method for setting a boundary on a variable within a script. I have this variable $name which is fed a value from $_POST['name'] from a form field. Now this form field is limited in the HTML to accept only 20 characters, but someone could easily edit the form or outgoing post data. So I want to know how to limit the variable size in the script. In other languages it could be something like this: var name(20). So how do I do that in PHP? 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 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 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."; } 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! 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 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.
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
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. This code works fine without the LIMIT 5, but it lists all the results. With the LIMIT Code: [Select] $query = 'SELECT * FROM wp_playerRank WHERE year="2011" LIMIT 5 ORDER BY rankClass ASC'; $results = mysql_query($query); while($line = mysql_fetch_assoc($results)) { Here is the error I'm getting: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/jwrbloom/public_html/resources/players/rank2011_top5.php on line 26 Hello friends, if i've database table (mytable) has the following ids 1 2 3 4 5 6 and i want to get it with limit the first (1 to 3 ) only Code: [Select] $sql ="select * from mytable LIMIT 3"; this will show the first 3 (1,2,3) how then i write code that shows which is after 3 so it shows me 4 5 6 and if there any way i can say Code: [Select] $sql ="select * from mytable LIMIT (first half of ids)"; and (shows 1,2,3..ect till half) Code: [Select] $sql ="select * from mytable LIMIT (second half of ids)"; will (shows 4,5,6...ect till end) thank you im using the floowing code to pull all alerts from the database. as you can see i have 3 types of alertsd. Profile alerts, forum alerts and topic alerts. They are sorted and placed on the screen under their respective header. However i want to limit it so it only displays 4 of each type of alert. I cant use LIMIT in the query because that would limit all alerts meaning only 4 alerts in total would show up and i just need to limit each alert type. any ideas? $alert_query = $link->query("SELECT a.a_aid, a.a_alert_type, a.a_time_alerted, a.a_fid, a.a_poster, a_alert_read, a.a_tid, c.f_name as cat_name, f.f_fid, f.f_name, t.t_name, u.u_avatar, u.u_avatar_cropped FROM ".TBL_PREFIX."alerts as a LEFT JOIN ".TBL_PREFIX."forums as f ON (f.f_fid = a.a_fid) LEFT JOIN ".TBL_PREFIX."topics as t ON (t.t_tid = a.a_tid) LEFT JOIN ".TBL_PREFIX."forums as c ON (c.f_fid = f.p_id) LEFT JOIN ".TBL_PREFIX."users as u ON (u.u_username = a.a_poster) WHERE a.a_user_name = '$user_name' ORDER BY a_time_alerted ") or die(print_link_error()); $alert_info = $alert_query->fetchAll(); $pm_alert_list = ''; $num_pm_alerts = 0; $num_forum_alerts = 0; $num_topic_alerts = 0; foreach($alert_info as $key => $val) { $alert_info[$key]['a_alert_read'] == 0 ? $color = '#f5dfaf' : $color = '#f4f4f4'; // if alert is a profile message alert if($alert_info[$key]['a_alert_type'] == 1) { $pm_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $pm_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" />'.profile_link($alert_info[$key]['a_poster']).' posted on your wall</p>'; $pm_alert_list .= '<p class="alert_time"> on '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $pm_alert_list .= '</dd>'; $num_pm_alerts++; } if($alert_info[$key]['a_alert_type'] == 2) { $forum_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $forum_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" /><strong><a href="'.$config['asf_root'].'category/'.create_url($alert_info[$key]['cat_name']).'/forum/'.create_url($alert_info[$key]['f_name']).'">'.$alert_info[$key]['f_name'].'</a></strong> has a new topic</p>'; $forum_alert_list .= '<p class="alert_time"> '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $forum_alert_list .= '</dd>'; $num_forum_alerts++; } if($alert_info[$key]['a_alert_type'] == 3) { $topic_alert_list .= '<dd style="background:'.$color.';" class="alert" id="alert-'.$alert_info[$key]['a_aid'].'"><p class="alert_intro">'; $topic_alert_list .= '<input type="checkbox" class="pm_checkbox" id="pm_checkbox-'.$alert_info[$key]['a_aid'].'" /><strong><a href="'.$config['asf_root'].'category/'.create_url($alert_info[$key]['cat_name']).'/forum/'.create_url($alert_info[$key]['f_name']).'/topic/'.create_url($alert_info[$key]['t_name']).'">'.$alert_info[$key]['t_name'].'</a></strong> has a new post</p>'; $topic_alert_list .= '<p class="alert_time"> '.asf_date($alert_info[$key]['a_time_alerted'],'full').'</p>'; $topic_alert_list .= '</dd>'; $num_topic_alerts++; } } 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? 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. 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.
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, |