PHP - Php Datetime To Mysql Date
I'm having trouble inserting a formatted PHP DateTime into a MySQL table.
I'm getting: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',2012-01-31)' at line 4 I get the error when I try to insert the date as a string from a DateTime object via: $insertDate = $date->format('Y-m-d'); As well as when I try to recast it as a date object: $insertDate = date("Y-m-d",strtotime($date->format('Y-m-d'))); I've also tried putting the date in ' ' 's and escaped " " 's. My insert query is: $insert = "INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('$partNum',$oQty,0,$aQty,'Excess',$price,$orderNum,'$tariffCode', '$location',$lineNum,$PKqty,$SPqty,'$allocDate');"; and the echoed output is: INSERT INTO pendingordersdetails (PartNumber,Oqty,Pqty,Aqty,PartStatus, PartPrice,idOrderNo,PrtTariffCode,PrtLocation,LineNum,PKqty,SPqty,AllocationDate) VALUES ('0446535240 ',3,0,1,'Excess',163.89,66,' ', 'A0406E01',2,,,'2012-01-31'); Anyone have any ideas? Similar TutorialsHi there,
I'm a bit of a newbie and I have done a search online, but i'm still confused.
I need to search my MYSQL database in a filed named date_mod I need to search for todays date only $date=gmdate("Y-m-d");
But however the field is a datetime option so how can I search only todays date and not both date and time.
Thank you for reading.
SELECT * FROM `booking_tbl` WHERE booking_status = 'Check In' AND departure_date_time = NOW()"I use the datetime datatype for the departure_date_time so i can get data from that data because it checking the date and time but i want it to check on the date from the datetime datatype So how can i get the data only with that date without the time in the mysql datetime datatype Alright, I have a Datetime field in my database which I'm trying to store information in. Here is my code to get my Datetime, however it's returning to me the wrong date. It's returning: 1969-12-31 19:00:00 $mysqldate = date( 'Y-m-d H:i:s', $phpdate ); $phpdate = strtotime( $mysqldate ); echo $mysqldate; Is there something wrong with it? What I'm basically trying to accomplish is, that the datetime of the user posted information is registered with the Now() function in the query, BUT that the user entered information gets echo'd out with the Date showing ONLY. What I have is this: -Just as an example- INSERT INTO db (date_created) VALUES (now()) while ($row = mysqli_fetch_array($data)) { echo '<tr><td>' . $row['date_created'] . '</td></tr>'; } mysqli_close($dbc); With this way of course I get Date and Time showcased just like it's inserted into the DB. What would be a legit way of showcasing just date. Thanks for help. EDIT: or is there a better way than using now() to showcase the date when the user entered information was posted? I have a field called date_time in the database which is of type datetime. I have a form which on submit needs to enter the current date and time in the date_time field. I know I can get the current time using time() $time=time(); Can do I do some kind of manipulation using strtotime() and store in the database in datetime format? I am using the following code to get the third sunday of every month for +6 Months from todays date. I have put together the following code which works perfectly when the date is echoed however when it comes to inserting those dates into mysql db it throws a unable to convert to string error. Im new to this and my head is in a spin as to why those dates can't be inserted if they can echoed ok. I have spent 2 days at it now and searched many forum however they seem to get side tracked from my issue (or do they)??????? I figure I can't go mixing DateTime and date() the way I have? Please help??? Code: [Select] [php] $month=date('F'); $now=date('Y-m-d'); $year=date('Y'); $num='3'; //example only this will be a $_POST value 0-3 $day='Sunday'; //example only this will be a $_POST value Monday-Sunday $start= date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.'')); if($start>$now) { $begin=strtotime('+'.$num.' week '.$day.' '.$month.' '.$year.''); } else { $d = new DateTime( $start ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $year = $d->format( 'Y' ); $begin=strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.''); } $date=date('Y-m-d', $begin); # insert into db first occurance //mysql_select_db($database); //$query_rsFirst = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsFirst = mysql_query($query_rsFirst) or die(mysql_error()); echo $date.'<br/>'; for($i = 0; $i <= 4; $i++) { $d = new DateTime( $date ); $d->modify( 'first day of next month' ); $nextmonth = $d->format( 'F' ); $date=date('Y-m-d', strtotime('+'.$num.' week '.$day.' '.$nextmonth.' '.$year.'')); # insert into db //mysql_select_db($database); //$query_rsDate = "INSERT INTO event_date VALUES (NULL, '$event', '$d', '$date', '$date')"; //$rsDate = mysql_query($query_rsDate) or die(mysql_error()); echo $date.'<br/>'; if($nextmonth=="December") { $d = new DateTime( $date ); $d->modify( 'first day of next year' ); $year = $d->format( 'Y' ); } } [/php] Dear all, how can I convert a string "yyyy-mm-dd hh:mm" into a really datetime value with php? thanks! I 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. 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 All, I need to subtract dates and display the number of days left. I have a 'Start' date and an 'End' date in DATETIME format in the DB. Not quite sure where to start. A simply start - end doesn't work . Start = 2011-11-01-00:00:00 End = 2011-11-30-23:59:59 Since it is now 2011-11-27, my output should equal 3. Any help is appreciated. Does anybody know how to take the queried standard date format - 2012-04-02 for example - and print it to the page as April 2, 2012? Or at the very least, to switch to 04-02-2012? Trying to find some tutorials online. I want to have a feature on a website I'm building where the user can select rows from a MySQL table based on it's age. For example they could select a piece of content between 30-60 days old. I'm going to do this using the following sequel "WHERE article_date BETWEEN 2010-12-01 AND 2010-11-01" However I'm not sure how to make this work. If the date is 2010-12-12 what is the easiest way to subtract 30 days from this date? Thanks for any help. What is difference between php date(); and mysql NOW() and what should be used in script? In php date I have 13:00h, and from MySql have 17:00h. Current date on my comp is 19:00h. So time difference in php is +6 hours, and in mysql is +2 hours. How to synchronize this dates for users??? im trying to crete a page that will search mysql for entrys from ??? days previous. ive not started on the php yet as i wanted to get the query done but im having a slight problem. date is in dd/mm/yyyy format. if i run this query SELECT * FROM `dsgi_serval` WHERE date >= '10/09/2010' it ONLY sorts by DD and not MM or YYYY, so anything greater than the 10th of the month shows regardless of what month. when i get to the php ill either do a drop down box with a preset number or days or a text box where u enter the number of days or even a txt box u enter the actual day u want to search from. im undecided which would be best. another problem i face with the php is how to tell the script to search from ? ?? when it says search from the past 3 days? <?php $date = date("d/m/y"); // todays date 04/12/2010 $_post= 3 days; // search from 01/12/2010 $date - $_post = $search; // 01/12/2010; $sql="SELECT * FROM $tbl_name" where date >= '$search'; echo the results ?> i no the above is not proper php but i hope it saya what im trying to do. Thanks Hello dear members, first of all sorry for my grammer i'm from Switzerland .
So now: I have a problem with php. I want to put out the date of a blogpost in this format dd:mm:yyyy instead of yyyy:mm:dd. I tried it a long time and used many different ways like: date, dateformat, strto etc. but at the and nothing worked for me. So here is a picture of the blogpost and i'll add the file with my compressd php code.
I'd be glad if you could help me
Regards Mr_Ironic i need a javascript date picker that will put a date in a text flied in the format of Y-m-d so that it can be posted to mysql also i need some kind of php to validite this Hello, this is my first time on this forum and also a modest newb on php, but i heard alot of people i know visit this site to get help on php. So i have a question, i know how to submit a form to mysql, the question is how do i recieve each indivual data i submit with the form by date and display it in order by date. i would like to submit kind of a status up everyday similar to twitter but order it by date and have it look kinda like: July 5, 2006 This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. July 4, 2006 This is a status example text that i will sumbit via form, links can be clicked and etc. This is a status example text that i will sumbit via form, links can be clicked and etc. Hi all I have an SQL database that holds dates in this format: yymmdd example: 110824 I am echoing the value: Code: [Select] <?php echo $showdata['date']; ?> How do I reverse the string so it shows 240811 ? Cheers Pete hello with tis button i generate some statistics from mysql if(isset($_POST['sub1'])) { $result = mysql_query("SELECT servitoros1, COUNT(*) from history WHERE serv LIKE '%be%' group by serv1"); while($row = mysql_fetch_row($result)) { echo "<tr>"; foreach($row as $cell) echo "<td ALIGN=\"center\">$cell<FONT></td>"; echo "</tr>\n"; } mysql_free_result($result); } but each record have datetime field!! so how can i set this display betwean 2 selectable datetimes e.g. from 2/2/2011 15:45 to 3/2/2011 23:59 hey guys the date stored in mysql is yyyy-mm-dd i need to convert it to do a string compare i have used the following $query = "SELECT * FROM booking where id=$sel"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $num1=$row['no_rooms']; $from1=$row['from']; $to=$row['to']; $sel1=$row['room_type']; $date = date('d-m-y', strtotime($from1)); } echo "$date"; it prints 01-01-70 can any1 tell me where is the error? thanks |