PHP - Moved: Help Adding A Time Stamp To A To-do List
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=306905.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=315056.0 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 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? 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()); 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..... 2011-02-05T18:07:57.00+0000 This is a string. 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'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()); 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 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=316461.0 Hi again guys, Right, I have two times being output from a database... The first time is the time something is booked in for (eg: 16:30:00) and the second time is the duration that thing is booked in for (eg an hour and a half - 01:30:00) Now, I want to figure out when that thing will be finished, so using the two examples above, it will be finished at 18:00:00, I've tried a few things with no success Please help Cheers 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.
I have a given date on a webpage, that I'm scraping to insert into a DB. The date is in this format: $date = 'Sun, Feb 9<br />3:00 PM ET': $healthy = array("<br />", " ET", "Sun.", "Mon.", "Tue.", "Wed.", "Thu", "Fri.", "Sat.", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); $yummy = array(" ", "2020", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); $date = str_replace($healthy, $yummy, $date1); $start = date('Y-m-d H:i:s', strtotime("$date -120 minutes"));
Ok, I have a variable ($incubation) set as 04:00:00. Then I have another variable ($starttime) set to the current time. Both are printing out fine. But I'm trying to get an $endtime from adding the incubation time to the start time. Code: [Select] $incubation = $row['incubation']; //IM GRABBING THIS TIME FROM THE DATABASE. It prints 04:00:00 $starttime = date("H:i:s"); //prints 16:23:39 $endtime = date("H:i:s", $starttime+$incubation); //prints 20:00:00 when it's suppose to print 20:23:39 I have am working on a shopping cart, for coupong buying. Here it only allows me to add one Item or One deal ata time into shopping cart. How can I change this code to accept more than one deal at a time before checking out. Code: [Select] { // add to cart /* $cart = unserialize(JFactory::getSession()->get('cart')); if (empty($cart)) $cart = new Cart(); */ // We only allow 1 item per cart from now one... $cart = new Cart(); $cart->addItem($deal); JFactory::getSession()->set('cart', serialize($cart)); $dealName = $deal->name; $buy4friend = $_GET['buy4friend']; $cartItemCount = $cart->getItem($dealId)->getCount(); if($buy4friend == 1) { $msg = $dealName . " :::<b> ". JText::_("DEAL_ADD_TO_CART_MESUN"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=viewCart&buy4friend=1", false); JFactory::getApplication()->redirect($link, $msg); }else{ $msg = $dealName . " ". JText::_( "DEAL_ADD_TO_CART"); $link = JRoute::_("index.php?option=com_enmasse&controller=shopping&task=viewCart&buy4friend=0", false); JFactory::getApplication()->redirect($link, $msg); } Hello people. Thank you to everyone who has helped me in the past, this is a great forum full of very helpful members. I am trying to put a pilots logbook application together for the members at microlightforum.com and here is the form that I have put together. What I would like to know is how to code the first "Auto Insert" button so that it takes the time from the variables $takeoff_hr and $takeoff_min and $landing_hr, $landing_min I would like the time difference from taking off to landing putting in the "ws_captain_hrs" box and the "ws_captain_min" box. Therefore if someone took off at 12.30 and landed at 13.50 the "ws_captain_hrs" box should read "1" and the "ws_captain_min" box should read "20" The idea behind this is that it makes it easier for the user to only have to insert take off time and landing time, then click the appropriate button to put the data into the box. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $host = 'localhost'; $usr = "vinny"; $password = 'thepassword'; $db_name = 'logbook'; $date = $_POST['date']; $type = $_POST['type']; $reg_01 = $_POST['reg_01']; $reg_02 = $_POST['reg_02']; $captain = $_POST['captain']; $passenger = $_POST['passenger']; $where_01 = $_POST['where_01']; $where_02 = $_POST['where_02']; $takeoff_hr = $_POST['takeoff_hr']; $takeoff_min = $_POST['takeoff_min']; $landing_hr = $_POST['landing_hr']; $landing_min = $_POST['landing_min']; $ws_captain_hrs = $_POST['ws_captain_hrs']; $ws_captain_min = $_POST['ws_captain_min']; $ws_student_hrs = $_POST['ws_student_hrs']; $ws_student_min = $_POST['ws_student_min']; $three_captain_hrs = $_POST['three_captain_hrs']; $three_captain_min = $_POST['three_captain_min']; $three_student_hrs = $_POST['three_student_hrs']; $three_student_min = $_POST['three_student_min']; $passenger_hrs = $_POST['passenger_hrs']; $passenger_min = $_POST['passenger_min']; $remarks = $_POST['remarks']; $errorstring = ""; // default value of errorstring if(isset($_POST['save_flight'])) { // Validate all the code inputs that are required fields if ($date =="") $errorstring = $errorstring. "Date<br>"; if ($type =="") $errorstring = $errorstring. "Aircraft Type<br>"; if ($reg_01 =="") $errorstring = $errorstring. "Reg Prefix<br>"; if ($reg_02 =="") $errorstring = $errorstring. "Registration Mark<br>"; if ($captain =="") $errorstring = $errorstring. "Captain<br>"; if ($where_01 =="") $errorstring = $errorstring. "Flight From<br>"; if ($where_02 =="") $errorstring = $errorstring. "Flight To<br>"; if ($takeoff_hr =="") $errorstring = $errorstring. "Takeoff Hours<br>"; if ($takeoff_min =="") $errorstring = $errorstring. "Takeoff Minutes<br>"; if ($landing_hr =="") $errorstring = $errorstring. "Landing Hours<br>"; if ($landing_min =="") $errorstring = $errorstring. "Landing Minutes<br>"; // does the errorstring = "nothing"? if ($errorstring !="") echo "You have not put anything in the following fields: <br><br> $errorstring"; //echo "If you have nothing to put in the box please type the word \"None\" or \"N\/A\""; //die ("Please try again, ensuring that you fill out all the fields!"); else { //echo "Your data has been saved"; //connect to database mysql_connect ("$host","$usr","$password") or die ('Error During Connect:<br>'.mysql_error()); mysql_select_db ("$db_name") or die ('Error Selecting DB:<br>'.mysql_error()); $insert_query = "INSERT INTO pilots_logbook (date, type, reg_01, reg_02, captain, passenger, where_01, where_02, takeoff_hr, takeoff_min, landing_hr, landing_min, ws_captain_hrs, ws_captain_min, ws_student_hrs, ws_student_min, three_captain_hrs, three_captain_min, three_student_hrs, three_student_min, passenger_hrs, passenger_min, remarks) VALUES ('$date', '$type', '$reg_01', '$reg_02', '$captain', '$passenger', '$where_01', '$where_02', '$takeoff_hr', '$takeoff_min', '$landing_hr', '$landing_min', '$ws_captain_hrs', '$ws_captain_min', '$ws_student_hrs', '$ws_student_min', '$three_captain_hrs', '$three_captain_min', '$three_student_hrs', '$three_student_min','$passenger_hrs', '$passenger_min', '$remarks')"; $insert_action = mysql_query($insert_query) or die ('Error During Insert :<br>'.mysql_error().'<br><br>Error occured running the following code :<br>'.$insert_query); $id = mysql_insert_id(); echo "Thank you, Your logbook entry has been saved."; } } ?> <p>Use this form to add an entry to your logbook.</p> <form name = "form1" method ="post" action=""> <table width="650" border="1" cellspacing="0" cellpadding="5"> <tr> <td>Required *</td> <td> </td> <td>This Format Only</td> </tr> <tr> <td width="180">Date *</td> <td width="300"> <input type="text" name="date" id="date" size = "25"/> </label> <input type="submit" name="today" id="today" value="Add Today" /></td> <td width="170">YYYY-MM-DD</td> </tr> <tr> <td>Aircraft Type *</td> <td><input type="text" name="type" id="type" size = "40" /></td> <td>E.G. Quantum</td> </tr> <tr> <td>Reg Number *</td> <td><input type="text" name="reg_01" id="reg_01" size = "5" /> - <input type="text" name="reg_02" id="reg_02" size = "15"/></td> <td>G - ABCD</td> </tr> <tr> <td>Captain *</td> <td><input type="text" name="captain" id="captain" size = "40" /></td> <td>Name of Captain</td> </tr> <tr> <td>Passenger or Student</td> <td><input type="text" name="passenger" id="passenger" size = "40" /></td> <td>Were you? P or S</td> </tr> <tr> <td>Flight From *</td> <td><input type="text" name="where_01" id="where_01" size = "40" /></td> <td>Take off Airfield</td> </tr> <tr> <td>Flight To *</td> <td><input type="text" name="where_02" id="where_02" size = "40" /></td> <td>Landing Airfield</td> </tr> <tr> <td>Takeoff GMT *</td> <td><label>Hr <input type="text" name="takeoff_hr" id="takeoff_hr" size = "10" /> Min <input type="text" name="takeoff_min" id="takeoff_min" size="10"/> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Landing GMT *</td> <td><label>Hr <input type="text" name="landing_hr" id="landing_hr" size="10" /> Min <input type="text" name="landing_min" id="landing_min" size="10" /> </label></td> <td>24 Hr Format Only</td> </tr> <tr> <td>Captain Weighshift</td> <td><label>Hrs <input type="text" name="ws_captain_hrs" id="ws_captain_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_captain_min" id="ws_captain_min" size = "10" /> <input type="submit" name="autofill_ws_captain" id="autofill_ws_captain" value="Auto Insert" /> <!--This is the button I would like to take the time from the take off and put it into the captain weightshift hrs and min boxes --> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student Weightshift</td> <td><label>Hrs <input type="text" name="ws_student_hrs" id="ws_student_hrs" size = "10"/></label> <label>Min <input type="text" name="ws_student_min" id="ws_student_min" size="10" /> <input type="submit" name="autofill_ws_student" id="autofill_ws_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Captain 3 Axis</td> <td><label>Hrs <input type="text" name="three_captain_hrs" id="three_captain_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_captain_min" id="three_captain_min" size = "10" /> <input type="submit" name="autofill_3_captain" id="autofill_3_captain" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Student 3 Axis</td> <td><label>Hrs <input type="text" name="three_student_hrs" id="three_student_hrs" size = "10"/> </label> <label>Min <input type="text" name="three_student_min" id="three_student_min" size = "10" /> <input type="submit" name="autofill_3_student" id="autofill_3_student" value="Auto Insert" /> </label></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Passenger Interest Only</td> <td>Hrs <input type="text" name="passenger_hrs" id="passenger_hrs" size="10"/> Min <input type="text" name="passenger_min" id="passenger_min" size="10"/> <input type="submit" name="passenger_button" id="passenger_button" value="Auto Insert" /></td> <td>Button works it out and inserts it here</td> </tr> <tr> <td>Remarks</td> <td><textarea name="remarks" id="remarks" cols="45" rows="5"></textarea></td> <td>Went to get microlight forum cup from XYZ airfield. Maximum 500 characters</td> </tr> <tr> <td><input type="submit" name="save_flight" id="save_flight" value="Save Flight" /></td> <td><input type="submit" name="reset" id="reset" value="Reset Form" /></td> <td> </td> </tr> </table> <p> </p> <p> </p> </body> </html> Hey guys! I have a list of times in this format: Code: [Select] Saturday 12:01 AM Saturday 12:09 AM And so on. I have about 200 times for each day of the week, in that same format. The list is stored in variable $times as an array. How can I have my PHP script find the next time in the list? For example, I have "Monday 1:53 PM". Right now, the time is 1:49 PM ("Monday 1:49 PM"). It needs to output 1:53 PM. I've tried so many things now Hi, I'm inserting hours and minutes per user into a database where they have their own fields. (userid, hours, mins) I've a small issue when displaying the data. When I run my query I sum the total hours and minutes per user which results in data such as the following userid1 - 2 hours 15 mins userid2 - 1 hour 100 mins The query orders by hours and then mins desc When I'm displaying the data (as I'm looping through the results array) I perform a calculation to convert the mins to hours so it now reads userid1 - 2 hours 15 mins userid2 - 2 hours 40 mins so the webpage displays userid1 first when i want userid2 to be the first record displayed (Hours desc) Can anyone recommend a solution to this ? Will I need to create another table and update it as hours and minutes are being entered and display results from that table instead ? Can I order the data after I carry out the mins to hours calculation ? many thanks in advance for any suggestions.... tmfl I want to users can setup time difference in hours, but I dont know how to solve this. Here is script for localtime: $date_format = 'd.m.Y H:i'; $timezone = new DateTimeZone("Europe/Berlin"); $date = new DateTime(); $date->setTimezone($timezone); echo "<div align='right'> Today is " . $date->format("$date_format") . "</div>"; Now I have $user_time in config and users can change this value (example: +1 hours, -3 hours etc...). Users time settings ($user_time) are saved in database. How to display time based on user_time (ex. $date->format("$date_format") ) to display message like this: Today is 16.09.2010 18 (+$user_time) : 40 |