PHP - How To Format A Date
I'm trying to format a date to use in a mysql query and was wondering about the best way to do it.
the form returns: mm/dd/yyyy and I need to format it to yyyy-mm-dd, any help would be greatly appretitaed, thanks in advance! 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. Hi Guys
In MYSQL the date format seems to be YYYY-MM-DD, when I use a dynamic table in Dreamweaver the date is also displayed this way, is there a simple way to change this to UK format DD-MM-YYYY?
I am trying to get the full date from form field using the date function and post method. $fromdate = $_POST[‘sdate’]; $todate = $_POST[‘edate’]; $fromday = date(‘F j, Y, g:i a’,’$fromdate’); $today1 = date(‘F j, Y, g:i a’,’$todate’); When trying to print i get the right format but i get extra information not sure from where? I am getting the date from the form fields of type date. Code Output: March 19, 2020, 4:16 pm,$31202019pm31Asia/Dubai why i am getting the second part! Hi Guys, I'm sure i have done this before, is there a way to shorten dates like: December 16, 2010 to Dec 16, 2010 and January 16, 2010 to Jan 16, 2010 etc, i have used $dateFormatted2 = date("F j, Y", strtotime($d2)); to get the date format i have now. any help would be appreciated thansk guys Graham Code: [Select] $date =date("d F Y"); It will display 18 October 2011. If I need it to display 2011-10-18. How do it go about coding it? What Date Format is this... Code: [Select] echo '<div class="date">Published: ' . date('F j, Y', strtotime($publishedOn)) . '</div>'; And where can I find a listing of the different Date and Time Formats that will work with this? (I would like to display my date as "2012-02-26 2:40pm" for what it is worth...) Thanks, Debbie Anyone know what's up with this? <?php $days = floor($posts['timestamp'] / (60 * 60 * 24)); $remainder = $posts['timestamp'] % (60 * 60 * 24); $hours = floor($remainder / (60 * 60)); $remainder = $remainder % (60 * 60); $minutes = floor($remainder / 60); $seconds = $remainder % 60; if($days > 0) { echo date("d/m/y", $posts['timestamp']); echo " at "; echo date("H:i", $posts['timestamp']); }elseif($days == 0 && $hours == 0 && $minutes == 0) { echo "few seconds ago"; }elseif($days == 0 && $hours == 0) { echo $minutes.' minutes ago'; }elseif($days == 0 && $hours > 0){ echo $hours.' hour ago'; }else{ echo "few seconds ago"; } ?> Hi guys I have this date script below which displays like so: 16/09/2011. Its fine but I now like it to display like this: 16 September 2011 Please I need help in twicking the code to do this Thanks! <?php //check to see if passing variable is set i.e. if true get day, month, year. if(isset($_GET['day'])){ $day = $_GET['day']; } else{ //Get today's date and put them in date, month, year $day = date("d"); } if(isset($_GET['month'])){ $month = $_GET['month']; } else{ $month = date("m"); } if(isset($_GET['year'])){ $year = $_GET['year']; } else{ $year = date("Y"); } echo $day."/".$month."/".$year; ?> I have a date field in the database table of this format 2012-02-08. Now I want to select fields from the database where date >= $currentdate. Do I have to do someting like $currentdate=time(); //Then convert it into YYYY-MM-DD format? I can't seem to get the syntax correct I want my date outputted as January 1st. Code: [Select] <span class="goal_head f_right mrm"><?php echo date($goal['complete_date'], 'F j'); ?></span> 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 I'm pulling some info from various XML files and am having problems converting the following date format so that it can be stored as a DATETIME field in a MySQL database. Tuesday,17 August 2010 09:25:00 This obvious newbie would appreciate a shove in the right direction... Thanks in advance I need to change the date format to DD-MM-YYYY. Please help. $SomeVar = $_POST['finco']; $query = "SELECT * FROM news_home WHERE code = '".$SomeVar."' ORDER BY timestamp DESC"; $results = mysql_query($query); $returnS=""; while($line = mysql_fetch_array($results)) { $returnS.= $line["subject"].",,".$line["timestamp"].",,".$line["News"].",,".$line["links"].",,,"; } echo $returnS; mysql_close($link); ?> Hi, I'm struggling a bit with using a date format and strtotime() Code: [Select] if(!empty($_GET['utime'])) { $time = strtotime($_GET['utime']); } utime is supplied in the format dd/mm/yyyy but when I use strtotime() it treats it as mm/dd/yyyy....so 07/12/2011 is taken as 12th Aug rather than 7th Dec..which is the date I want to use. I had a quick ganders through the forums but couldn't find anything specific to this. is there any other attributes to strtotime() that will help, or a similar fucntion or a neat way of swoping my dd/mm/yyyy round before i use strtotime() any help greatly appreciated... 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'm trying to make $time be a variable with the current time and I want it to have the same format as mysql. I can't figure out what I am doing wrong here Wrror: Warning: date_format() expects parameter 1 to be DateTime, integer given Code: [Select] $time = date_format(time(),'Y-m-d H:i:s'); Hi i've been trying to change the format of the date which comes from the database row [ news-date ] this what i tried but di not work help please $query = "SELECT * FROM news, date_format [news_date](date,'%M %d, %Y') AS news_date "; $result = mysql_query($query); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes so print them one after another echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$row["news_id"]."</td>"; echo "<td>".$row["subject"]."</td>"; echo "<td>" .$row['news_date']. "</td>"; echo "<td>".$row["news_artical"]."</td>"; echo "<td><a href=delete2.php?id=".$row["id"].">Delete</a></td>"; echo "<td><a href=modifyform.php?id=".$row["id"].">Modify</a></td>"; echo "<td><a href=add.php?id=".$row["id"].">Add Row</a></td>"; echo "</tr>"; } //End While echo "</table>"; } //End if rows echo "<p> <strong>{news.SUBJECT} </strong></p>"; ?> Hi there, i want to convert whatever a user inputs through and html form to a DATE format which when posted will be entered (using mysql) as that particular Date format , i'm using this: Code: [Select] $date = "12-12-11"; //assume this to be the user input $time = strtotime($date); $new_date = date("d/m/Y",$time); echo $new_date; but this format will give the output as: 11/12/2012.....is there a way to convert whatever the user enters to be: dd/mm/yyyy which gives: 12/12/2011 thanks so much
I am currently using a product called PhPRunner.
|