PHP - Difference In Time Stamp
hello, im trying to figure out the difference between 2 numbers in minutes. here is what i have:
Code: [Select] $tsignin="09-05 10:30:00"; $tsignina="09-06 11:30:00"; $log_in_time_stringsa = strtotime($tsignin); $log_out_time_stringsa = strtotime($tsignina); $difference_in_secondssa = ($log_out_time_stringsa - $log_in_time_stringsa); $tsigna = ($difference_in_secondssa / 60); $tsigna2 = number_format(round($tsigna)); the 09-05 is sept 5, and 09-06 is sept 6. this works if the month and date are not included. any ideas for me so i can figure out the total difference between date/times? Similar TutorialsBasically 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 Hello, i need a fast convertor that converts the date format 03-03-2008, 08:26 PM into a timestamp fast. Like, you paste 03-03-2008, 08:26 PM into a post form, submit and it gives you the time stamp. I made a convertor a whille ago, but you need to insert each numbers into a separate input box (day, months, year etc) I cant remember how exactly it functions etc asi haventtouched PHP In a while..... I have this code to change the validity date of an account. I do a check against timestamp and current validity which works fine. Then I have radio buttons you can check to choose to extend with one, three, six or 12 months through a form and a post variable - they work too. When I write the variables out they look fine but when I want it in my database - nothing happens! I mean the original data is never changed. Can you see what is wrong? I tried changing the data type from date to datetime to timestamp with the same result. I suppose I will learn something new from phpfreaks today again. Code is here for the 12 month radio button: Code: [Select] $newdate = strtotime ( '+12 months' , strtotime ($fromDate) ) ; $newdate = date ('Y-m-d H:i:s', $newdate ); echo "$newdate"; $query = "UPDATE TABLE user_data SET paid_days='$newdate' WHERE user='$user'"; mysql_query($query);When I write the variable $newdate it shows up as 2013-01-10 21:55 (right now) which seems like a valid format to me. Do I need to convert it somehow? I am trying to enter a new time stamp into mysql database when a user logs in at my site. I read on the update syntax but can't seem to get it to do it.. It reads the values just doesnt write the values into mysql. $update_query = mysql_query UPDATE users SET (last_access, ip_address, browser, hostname) values ($date, $IP, $browser, $hostname) WHERE username = '$login'") or die("QUERY FAILED: " . mysql_error()); $update = ($update_query) or die ("QUERY FAILED: " . mysql_error()); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315056.0 2011-02-05T18:07:57.00+0000 This is a string. I'm having a problem with getting the timestamp to attach to the filename. Currently when it's uploaded in the database it says $timestamp in front of the filename instead of the time. Scroll down towards the bottom of the code to see it. Thanks for your help! $username = $_GET['username']; $item_id = $_GET['id']; define( 'DESIRED_IMAGE_WIDTH', 150 ); define( 'DESIRED_IMAGE_HEIGHT', 150 ); $source_path = $_FILES[ 'thumb' ][ 'tmp_name' ]; $timestamp = time(); // // Add file validation code here // list( $source_width, $source_height, $source_type ) = getimagesize( $source_path ); switch ( $source_type ) { case IMAGETYPE_GIF: $source_gdim = imagecreatefromgif( $source_path ); break; case IMAGETYPE_JPEG: $source_gdim = imagecreatefromjpeg( $source_path ); break; case IMAGETYPE_PNG: $source_gdim = imagecreatefrompng( $source_path ); break; } $source_aspect_ratio = $source_width / $source_height; $desired_aspect_ratio = DESIRED_IMAGE_WIDTH / DESIRED_IMAGE_HEIGHT; if ( $source_aspect_ratio > $desired_aspect_ratio ) { // // Triggered when source image is wider // $temp_height = DESIRED_IMAGE_HEIGHT; $temp_width = ( int ) ( DESIRED_IMAGE_HEIGHT * $source_aspect_ratio ); } else { // // Triggered otherwise (i.e. source image is similar or taller) // $temp_width = DESIRED_IMAGE_WIDTH; $temp_height = ( int ) ( DESIRED_IMAGE_WIDTH / $source_aspect_ratio ); } // // Resize the image into a temporary GD image // $temp_gdim = imagecreatetruecolor( $temp_width, $temp_height ); imagecopyresampled( $temp_gdim, $source_gdim, 0, 0, 0, 0, $temp_width, $temp_height, $source_width, $source_height ); // // Copy cropped region from temporary image into the desired GD image // $x0 = ( $temp_width - DESIRED_IMAGE_WIDTH ) / 2; $y0 = ( $temp_height - DESIRED_IMAGE_HEIGHT ) / 2; $desired_gdim = imagecreatetruecolor( DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); imagecopy( $desired_gdim, $temp_gdim, 0, 0, $x0, $y0, DESIRED_IMAGE_WIDTH, DESIRED_IMAGE_HEIGHT ); // // Render the image // Alternatively, you can save the image in file-system or database // header( 'Content-type: image/jpeg' ); imagejpeg( $desired_gdim, "image_files/".'$timestamp'.$_FILES["thumb"]["name"] ); mysql_connect("localhost", "root", "", "") or die(mysql_error()); mysql_select_db("") or die(mysql_error()); $timestamp = time(); $item_image = '"$timestamp"'.$_FILES['thumb']['name']; $sql="UPDATE product SET thumb='$item_image' WHERE id = '$item_id'"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=306905.0 Code: [Select] for ($z=1;$z<=30*365; $z++) { $bal[date('Y-m-d', strtotime("+ ". $z ." days"))] = $balance;//the balance of loan here.; } As you can see Im working on loading the daily balance of a 30 year loan in an array. The code goes to hell in the year 2038. I have scoured the internet for help. I have gone to the wikipedia link and have looked at other posts but there isn't quite something that can help me. How can I load dates beyond 01-18-2038 into my array? I have heard of ways to do it with MySQL and the DATETIME() function, but that doesn't seem to make sense for what I am trying to accomplish. Please point me in the right direction. Thanks. Hi everyone... I would like to implement a questionnaire/survey system that has only two Answers (Yes /No). Basically, this questionnaire system will be widely used on Mobile Phones. It will be looking something like this below: http://awardwinningfjords.com/2009/06/16/iphone-style-checkboxes.html Lets say a user selects a response as No (Using the above slider button for a question). That response should be recorded in the database with User Details + Time Stamp. Also, I would like to generate a report for each question (Responses of Multiple Users) and a report at a User Level for the entire questionnaire/survey (s). Can some one guide me the fastest & easiest way to achieve this? I'm a new learner of PHP. Regards Sandeep i have searched everywhere and no code seems to work. i have time1 and time 2 in the format Y-m-d H:i:s. i just don't know how to find the difference. old time: 2011-04-11 20:15:46 new time: 2011-04-11 21:00:11 after i have the difference, i need to get a resource production per hour which is stored in the database and calculate the new value of the resource. $production_per_hour = 100; $time_old = "2011-04-11 20:15:46"; $time_new = "2011-04-11 21:00:11"; $current_resources = "500"; hiii, Im wanting to calculate the time difference between $out2 and $in2 and out put it into a spreadsheet: Code: [Select] $m=0; while ($m < $num9) { $fullname=mysql_result($result9,$m,"username"); $date=mysql_result($result9,$m,"date"); $in1=mysql_result($result9,$m,"in1"); $out1=mysql_result($result9,$m,"out1"); $in2=mysql_result($result9,$m,"in2"); $out2=mysql_result($result9,$m,"out2"); $out2f=date("G:i:s",strtotime($out2)); $in2f=date("G:i:s",strtotime($in2)); echo date("D",strtotime($date)). "\t" . $fullname . "\t" . $in1 . "\t". $out1 . "\t" . $in2 . "\t" . $out2 . "\t" . date("G:i:s",strtotime($out2f-$in2f)) . "\t" . "\n"; $m++; } header("Content-disposition: attachment; filename=spreadsheet.xls"); why does this code return 00:00:00 ? Problem; Need to check to see if someone who requested a password re-set has done so with in 24hrs. IF not- then it needs to prompt them to re-submit the request and deletes the previous re-submit code sent to them in their email. I have everything else figured out (deleting re-set code) but I have not figured the checking of if they have done so within the 24hr time period. Please tell me if the code below will accurately tell me if they complied with the 24 hour rule. $time1 = '1284675867';// logged at the time of password re-set request. Retrieved from database $time2 = time();// captured in script when they actually re-set their password $difference_between = $time2 - $time1; if($difference_between >= '5,200,000') { echo "Sorry- you have exceeded the 24 hr rule and need to re-submit your request"; } Compared to all that I have seen.........it appears rather simplistic. Am I missing something or will this simple approach work? For some reason when I echo $diff and $time_remaining it ALWAYS echos with values of 3 and 7 and not sure why. Code: [Select] $lock_date = $row['lock_date']; $current_time = time(); // Find out if user is locked out of their account if (($lock_date != "0000-00-00 00:00:00") && strtotime($lock_date) < $current_time) { $lock_date = strtotime($lock_date); $diff = $current_time - $lock_date; $diff = floor($diff/6000); // Take minutes and perform tasks if ($diff <= 10) { // Calculate time remaining $time_remaining = 10 - $diff; // Account locked error $errors = true; $message = "Account is locked! Must wait " .$time_remaining." minutes to log in again!"; $output = array('errorsExist' => $errors, 'message' => $message); } else { // Clear the lock $query = "UPDATE users_logins_attempts SET lockDate = NULL, ip_address = NULL, failed_logins = 0 WHERE users_id = '".$users_id."'"; $result = mysqli_query($dbc,$query); // Account locked error $errors = true; $message = "Account is unlocked. You may now try to log in again!"; $output = array('errorsExist' => $errors, 'message' => $message); } } Hi, I am trying to get the difference in time in mins, hours etc thingy. Now, for some reason I cannot get the right minutes or hours difference between two time stamps. Here is my code: Code: [Select] $postedTime=strtotime($comment_from_db->date_posted); $currentTime=time(); $mins=floor(($currentTime-$postedTime)/60); if($mins<=1){ echo $mins." minute ago by"; }elseif($mins>1){ if($mins>60){ $hrs=floor($mins/60); if($hrs>24){ }else{ if($hrs<2){ echo $hrs. " hour ago by"; }else{ echo $hrs. " hours ago by"; } } }else{ echo $mins." minutes ago by"; } } Now, for a comment posted like 25 mins ago it shows it was posted 4 hours ago. For a comment posted around 10 hours ago it shows it was posted 16 hours ago. What is the problem here? I was doing a test and checked the time in seconds after an interval of 2 mins. Here are the results: Comment posted: 1306669490 Current time: 1306683920 The difference is around 14430. This is not equal to 2 minutes. So, I am starting to think if the time I am getting is wrong? Should it have 10 digits? or less? I am not sure what is going on. Please, advice. Thanks. Hey guys, What i would like to create is the ability to calculate the difference between two dates / times. For example: 2010-12-13 10:00:00 to 2010-12-17 17:00:00 In a format of days / hours and minutes / seconds. However, I only want to calculate for an 9-5 work day, not the hours outside. Is this possible? If so, how would I go about creating something like this. Hi, Trying to figure out a way to get a time difference between two times assuming they are in order.. For example; in the array below the days is easy.. because the time happens later, however nights it becomes a little more confusing. The method I'm using now is; if the dates are in order just stick a reference date on there, and get a difference. If they seem to be reversed, I stick a reference date on the first one and a reference date +1 days on the second and get the difference.Can you all think of a better way? I will use the assumption that the times will NEVER be more than 24 hrs apart..
Array ( [2] => Array ( [days] => Array ( [0] => 07:00:00 [1] => 15:45:00 ) [nights] => Array ( [0] => 15:30:00 [1] => 02:15:00 ) )
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. I have two textboxes that inputted time, and I want to get the difference between two time. for example: $IN = 13:35; $OUT = 17:35; $OTHours = ($OUT - $IN); $OTHours = 4.00; and it is correct, but I have a scenario like this: $IN = 21:35; $OUT = 05:35; $OTHours = -16.00; it should be 8.00. Any help is highly appreciated. Thank you.. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310181.0 |