PHP - Convert Date Format From Form Input Before Query
Hi. I have an input field where a date is entered, format dd-mm-yy. I need to query the database to see if this date exists. How can I convert the date to yyyymmdd before the query?
Thanks Similar TutorialsI have tried a large number of "solutions" to this but everytime I use them I see 0000-00-00 in my date field instead of the date even though I echoed and can see that the date looks correct. Here's where I'm at: I have a drop down for the month (1-12) and date fields (1-31) as well as a text input field for the year. Using the POST array, I have combined them into the xxxx-xx-xx format that I am using in my field as a date field in mysql. <code> $date_value =$_POST['year'].'-'.$_POST['month'].'-'.$_POST['day']; echo $date_value; </code> This outputs 2012-5-7 in my test echo but 0000-00-00 in the database. I have tried unsuccessfully to use in a numberof suggested versions of: strtotime() mktime Any help would be extremely appreciated. I am aware that I need to validate this data and insure that it is a valid date. That I'm okay with. I would like some help on getting it into the database. while I'm reading the cell value '20/09/1980' from an excel file using phpexcel class method $student[$i]['d_o_b'] = $objWorksheet->getCell('G' . $intRow)->getValue(); getting the value as '29484' pls help me to convert it into the date format again. I have a calendar select date function for my form that returns the date in the calendar format for USA: 02/16/2012. I need to have this appear as is for the form and in the db for the 'record_date' column, but I need to format this date in mysql DATE format (2012-02-16) and submit it at the same time with another column name 'new_date' in the database in a hidden input field. Is there a way to do this possibly with a temporary table or something? Any ideas would be welcome. Doug I wish to know how i can convert this date 24-09-2010 to this format 2010-09-24
Hello All, function convertTimeFormat($time12Hour) { // Initialized required variable to an empty string. $time24Hour = ""; // Used explode() function to break the string into an array and stored its value in $Split variable. $Split = explode(":",$time12Hour); // print_r(explode (":", $time12Hour)); => Array ( [0] => 09 [1] => 50 [2] => 08AM ) // Retrieved only "hour" from the array and stored in $Hour variable. $Hour = $Split[0]; $Split[2] = substr($Split[2],0,2); // Used stripos() function to find the position of the first occurrence of a string inside another string. if($Hour == '12' && strpos($time12Hour,"AM")!== FALSE) { // Code here } elseif(strpos($time12Hour,"PM")!== FALSE && $Hour != "12") { // code here } return $time24Hour; } $time12Hour = "09:50:08AM"; $result = convertTimeFormat($time12Hour); print_r($result); /* Input : "09:50:08AM"; Output : "21:50:08PM"; */
Hi all, I am currently making a website that has e-custom functions and a back end for the client. I want them to be able to upload images - but they need to be transparent. I do not want to leave this in the hands of the client, so I am looking at ways of using the GD library to make the change I got no issue with the png/gif type for upload/resize function since this type already transparent background but my major problems is how to deal with jpeg/jpg image type which is their background was not a transparent...so is it possible I can change/ convert to png/gif type upon successful of uploading image...so the new final image will be png/gif type with transparent background...is it doable...I am not even sure it is possible...? Thanks for any help.. Well the topic may not sound very explicit. So I'll do my best to explain it here. I have a pull down menu as part of a form, which contains the months of the year. I'm trying to store the value of this form entry using the $_POST['month'] variable into a database but first, I need to convert the month values into their corresponding integer values( that is 1 for January, 2 for February etc), in order to easily do date calculations later down the road. Any ideas about how to do this? It may be helpful to include the code for the pull down menu. Code: [Select] <p><tab> Date of Birth: <?php //Make the month pull down menu. //Array to store months. $months = array (1 => 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); print '<select name= "month">'; foreach ($months as $key => $value) { print "\n<option value=\"$key\">$value</option>"; } print '</select>'; ?> </tab> <tab> <?php //Make the day pull down menu print '<select name= "day">'; for ($day = 1; $day <= 31; $day++) { print "\n<option value=\"$day\">$day</option>"; } print '</select>'; ?> </tab> <tab><?php //Make the year pull down menu print '<select name= "year">'; $start_year = date('Y'); for ($y = ($start_year - 18); $y >= 1900; $y--) { print "\n<option value=\"$y\">$y</option>"; } print '</select>'; ?> </tab> </p> Hello all,
I am completely sideways right now trying to get this to work. Basically I am attempting to make a form that fetches results based on a drop down and then populates a text box that the user can then edit. I have several issues, first of all, I would have to use check boxes for if a user has a certain file on record. Which would be editable, however, I have had issues displaying tinyint values of -1 as true and 0 as false.
Secondly, writing the data back to the table after clicking a submit button, I have still issues with checkboxes here and am thoroughly confused to if I need to use an array or what here.
Thirdly, should I be using PDO or mysql for this? We have an older NAS device that I will be running this on and the firmware is older.
All the info is stored in the same table, and would be selecting a single record at a time for a user to edit. I was thinking I would just write back ALL values to the table when submit is clicked? Is that a bad idea?
As you can tell I just need someone to kick my butt in the right direction, I feel like I have read all the different ways to skin a cat but confused myself in the process.
Thanks
Hi I was going to start a new project which need to convert files from one fomrat to other like, you can check a site here online-convert.com , there they give user to convert in various fomats. please check my question is i have idea how to do these conversion with ffmpeg and php. Code: [Select] Audio converter Video converter Image converter Hash generator can someone please tell me how to do these conversion. Code: [Select] Document converter Ebook converter Thanks for any help Can anyone please tell me how I convert DD-MM-YYY (text) to TIME (unix) thought I'd say that I have this line at the top of all my pages, just in case it means a different code. Code: [Select] date_default_timezone_set('Europe/London'); //### Set the default timezone I have multiple datetimes. The format is dd-mm-yy, hh:mm. I want to insert it into a table using mysql. However mysql format is yy-mm-dd, hh:mm:ss. How can i do it and what type should i use (datetime?timestamp?). Thanks for your help!! Hi, I am trying to convert a String date into numeric date using PHP function's, but haven't found such function. Had a look at date(), strtotime(), getdate(); e.g. Apr 1 2011 -> 04-01-2011 Could someone please shed some light on this? Regards, Abhishek Hi, I need to post to a form with cURL. I'am sending strings in Headers format... There are some documentation or some function that translates from the human readable format to the Headers format? For example: Human readable format: Quote Vendo bicicleta. Como nova. Headers format: Quote Vendo%20bicicleta.%20Como%20nova. The problem is not the spaces but more the accents. I write in Portuguese. Can you give me some clue? Best Regards, Does anyone know how I can convert linux epoch number such as 1292878800 to the UTC format? Ricky Hi there, I have a string '12/04/1990', that's in the format dd/mm/yyyy. I'm attempting to convert that string to a Date, and then insert that date into a MySQL DATE field. The problem is, every time I try to do so, I keep getting values like this in the database: 1970-01-01. Any ideas? Much appreciated. Hi, I have a connection set up to an API using a PHP script - the API sends back data in JSON format, and if I capture it and echo it, it displays in extremely unfriendly format on the screen. I've tried to find a way to convert this data into readable format, ideally in a HTML table, but although there are articles on converting manually inputted JSON data into a HTML table using Javascript, I can't find a way to do it from a PHP variable. This is what I have so far: if ($_POST['getcompany']) { $companyname = $_POST['_Name']; $ch = curl_init(); $data_array2 = array( 'token' => $token ); $make_call2 = json_encode($data_array2); //echo 'Token is '.$token; $token2 = substr($token, 14); $token3 = substr($token2, 0, -3); //echo 'Token 2 is '.$token3; //echo 'Company Name is '.$companyname; //curl_setopt($ch, CURLOPT_GET, 1); //curl_setopt($ch, CURLOPT_POSTFIELDS, $make_call2); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json','Authorization: '.$token3.'')); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_URL, 'https://connectionurl?countries=GB&name='.$companyname); //Execute the request $result = curl_exec($ch); echo 'Companies: '.$result; //This displays the data provided by the search, but is in JSON format
So I need a way to get the data held in $result, into a HTML table. Any idea how I can do this? Hi In sql we have dates like this 134238 In php it shows - 19:10:11 . we can make it by using date('d.m.y', $date); where $date=134238 ; my question is how can we turn 19:10:11 in to 134238 using PHP Is it possible to convert time(); to date();? Hi all, I'm having a bit of trouble a script running on a site where it converts a date of birth in a database shown like this '30/04/1993' to an actual age, for instance 18 in this case. Only the script I'm using below shows this age as 17, not 18 as it should be. Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($day,$month,$year) = explode("/",$birthday); $day_diff = date("d") - $day; $month_diff = date("m") - $month; $year_diff = date("Y") - $year; if ($day_diff < 0 || $month_diff < 0) $year_diff--; return $year_diff; } ?> So i've tried to remedy this myself with the following: Code: [Select] <?php $birthday = $row_getdets['dob']; function birthday ($birthday){ list($year,$month,$day) = explode("/",$birthday); $year_diff = date("Y") - $year; $month_diff = date("m") - $month; $day_diff = date("d") - $day; if ($month_diff < 0) $year_diff--; else if (($month_diff==0) && ($day_diff < 0)) $year_diff--; return $year_diff; } ?> ..but I'm having a syntax error (unexpected T_LINE), most probably down to my novice ability, I bet I've missed something simple. I'm still learning guys and I'd really appreciate any help at all. Hi Guys Could somebody tell me how i would put a line break into the code below i.e: 1.07 <br /> 2010 <?php echo date('d.m.Y',strtotime($news['created_at']));?> Thanks for your help |