PHP - Format Date From Value In Table
Hey, I am grabbing a date from a row in my table which is currently formatted as:
date("Y-m-d") 2010-09-29 So in my code I have something like this: $row['date']; How do I use this to rearrange the date to look like: 09-29-2010 I looked at the formatting tutorials, but they explain how to format it for the date you are currently setting into a variable. Similar TutorialsHi all - I am parsing info from mysql into a php table but the date being returned is in YYYY-MM-DD format and I want it DD-MM-YYYY. How would I do this? Code at the moment is: Code: [Select] $link = connect(); function get_user_posts(){ $getPosts = mysql_query('SELECT a.id as id,a.post as question, a.answer as answer, a.created as created, a.updated as updated, b.vclogin as admin FROM user_posts as a, admin as b WHERE a.admin_id=b.adminid',connect()); return $getPosts; } Code: [Select] <table class="list"> <tr> <th><?php echo getlocal("upost.post") ?></th> <th><?php echo getlocal("upost.answer") ?></th> <th><?php echo getlocal("upost.admin") ?></th> <th><?php echo getlocal("upost.created") ?></th> <th><?php echo getlocal("upost.updated") ?></th> <th></th> <th></th> </tr> <?php $all_questions = get_user_posts(); while ($question = mysql_fetch_assoc($all_posts)): ?> <tr> <td><?php echo $post['post']?></td> <td><?php echo $post['answer']?></td> <td><?php echo $post['admin']?></td> <td><?php echo $post['created']?></td> <td><?php echo $post['updated']?></td> <td><a href="javascript:user_post('<?php echo $post['id']?>')">edit</a></td> <td><a href="javascript:delete_post('<?php echo $post['id']?>')">delete</a></td> </tr> THANKS! I have a simple mysql database holding information about an image upload including its 'name' and 'date uploaded' [current_timestamp()] to a folder 'image' I then display it into a table using the php ‘foreach’ facility. I want the date to be displayed in the ‘dd/mm/yyyy’ format. not the default yyyy/mm/dd. Here is the relevant code <?php $conn = mysqli_connect("localhost", "root", "", "dbname"); $results = mysqli_query($conn, "SELECT * FROM tablename"); $image = mysqli_fetch_all($results, MYSQLI_ASSOC); ?> <?php foreach ($image as $user): ?> <td><p>NAME</p><?php echo $user['name']; ?></td> <td><p>COMMENT</p><?php echo $user['comment']; ?></td> <td><p>DATE</p><?php echo $user['date']; ?></td> What do I need to do? THANKS- Warren 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 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 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! 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? 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! 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?
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 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? 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 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 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 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> 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'); I want the current date to be displayed in this format: year-month-day hr:min:sec Suggest me some functions or codings 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); ?> 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 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>"; ?> |