PHP - Php/mysql Date
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. 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. 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. 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'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? guys, im having a problem here thats making me crazy im making a system and i want to insert the current date in the mysql. I have the field called 'data' in the DB, but when i make the code to insert all the other fields, including the 'data', its work perfectly... unless that damn date! $query = "INSERT INTO news (id, titulo, mensagem, data) VALUES (NULL, '$titulo', '$mensagem', 'date(\"d/m/Y\")')"; whats wrong with that? its stores in DB as '0000-00-00'. 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 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 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, I would like to order by date that contains day and month, like this: 14-3 Is this possible? Quote $sql = mysql_query("SELECT * FROM date WHERE online='1'"); 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, 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. 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 Hi, I'm trying to insert this $inceptiondate = date("Y-m-d 12:00:00"); to the database, the Y-m-d does make it to database, but the 12:00pm doesn't. Whenever it reaches the database, it becomes 00:00:00 Where did I got wrong? Thanks Hi Guys,
Been trying to make it that when I insert into Mysql at the moment it inserts like dd-mm-yy, however cause I'm in the UK i need it to do it in the UK way of dd-mm-yy I checked out some topics and found the STR_DATE_DATE however I've tried to use it in my mysql but cannot get it to work. Can someone help
$query="INSERT INTO job_scheduled (startdate, enddate, job_title, job_reference, job_description, job_postcode, job_city, customername, customer_email, status) VALUES ('".STR_TO_DATE($_SESSION["startdate"],'%d-%m-%y')."', '".$_SESSION["enddate"]."', '".$_SESSION["job_title"]."', '".$_SESSION["job_reference"]."', '".$_SESSION["job_description"]."', '".$_SESSION["job_postcode"]."', '".$_SESSION["job_city"]."', '".$_SESSION["customername"]."', '".$_SESSION["customer_email"]."', 'Provisional')"; Hi all I am trying to write a script that takes the filename and username from a form and adds it into a mySQL database. At the moment only the username is added? Here's my code: <?php include('includes/connection.php'); $username = $_POST['username']; date_default_timezone_set('Europe/London'); // Change time zone to GMT $date = date ('D M j G:i:s'); // Set date format $path= "/home/cndvizp/public_html/prints2impress.co.uk/images/uploads/".$HTTP_POST_FILES['ufile']['name']; if($ufile !=none) { if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)) { //insert new query $filename = $_FILES['ufile']['name']; $pfw_strQuery = "INSERT INTO `uploads`(`username`,`url`,`date_entered`)VALUES (\"$username\",\"$filename\",\"$date\")" ; $pfw_result = mysql_query($pfw_strQuery); if (!$pfw_result) { die('Invalid query: ' . mysql_error()); } //include ('payment.php'); echo 'done'; } else { //include ('error.php'); echo 'error!'; exit; } } ?> Can anyone help me get the filename and the date to be added? Cheers Pete. So I'm trying to put a user selected date into a mysql query, but it seems like no matter what I do I get 0 results even though I already know there's quite a few. The way I have it now 'echo $query;' puts out the expected results, but I'm guessing it's because I'm trying to match a date to a string. I tried strtotime but I'm not sure if I was doing it right.. I also tried sprintf() just in case, but that doesn't seem to have a date feature. The variable $realdate is just to show how I was attempting to use strtotime, it's not an actualy part of the script at this time... $searchdate = $_GET['searchdate']; //$realdate = strtotime($searchdate) //connects to db dbconnect(); $query="SELECT `name`, `date`, SUM(`amount`) as `total_money`, SUM(`bricks`) as `total_bricks` FROM Aces_Donations WHERE `date`= $searchdate ORDER BY `total_money`"; echo $query; $result=mysql_query($query); //Opens the table echo "<table border = '3' width = 40% bgcolor=#A85045><caption><center>Rankings - ".$searchdate.'</center></caption>'; //Loop to run until eof while($row = mysql_fetch_array($result)){ echo "<tr><td>".$rank."</td> <td>".$row['name']. "</td><td>". $row['total_money']."</td><td>".$row['total_bricks'].'</td></tr>'; $rank++; } echo '</table>'; How would I put today date for instance into mysql_query? I just want the date and have the format be year, month, day. The format in the database looks like 2010-04-05. That being used as an example. And I have three drop down menus, which you can select the year, month, and day, but it doesn't seem to be working. What am I doing wrong? Hi 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.
|