perficut Posted October 27, 2009 Share Posted October 27, 2009 I am starting small and this is probably very trivial for most of you but I am trying to grasp this as best I can. I have a datafile which has a filed called ReqDate and is set as a timestamp field. For simplicity sake, I wanted to display all the records in my database. Which I was able to do. However, the ReqDate comes out a fit funky. Is there a way to convert the provided timestamp with a DD/MM/YYYY format? Heres the what I have so far. <?php // Make a MySQL Connection mysql_connect("localhost", "login","pw") or die(mysql_error()); mysql_select_db("mydatafile") or die(mysql_error()); // Get all the data from the "example" table $result = mysql_query("SELECT * FROM ILCustomers") or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>Name</th> <th>Age</th> <th>Request Date</th></tr>"; // keeps getting the next row until there are no more to get while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['City']; echo "</td><td>"; echo $row['State']; echo "</td><td>"; echo $row['ReqDate']; echo "</td></tr>"; } echo "</table>"; ?> Also I would like to display a final column which is NOT a field in my database. This column I would like it to take the data from the ReqDate and add 14 days to it then display it in the last column of the display table. Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/ Share on other sites More sharing options...
Alex Posted October 27, 2009 Share Posted October 27, 2009 For the first problem just use date() to format the timestamp. For the second problem do the same thing but just add 14 days to the timestamp. eg echo date('some format..', $timestamp); echo date('some format..', $timestamp + 60*60*24*7*2); Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/#findComment-945801 Share on other sites More sharing options...
perficut Posted October 27, 2009 Author Share Posted October 27, 2009 thank you Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/#findComment-945817 Share on other sites More sharing options...
perficut Posted October 28, 2009 Author Share Posted October 28, 2009 Heres what I have, and I what I am getting. I cant figure out how to convert the closed_date to show the right data. while($row = mysql_fetch_array( $result )) { // Print out the contents of each row into a table $date_requested=date("F j, Y ", strtotime($row['ReqDate'])); $date_closed=strtotime(date("F j, Y ", strtotime($date_requested)) . " +1 week"); echo "<tr><td>"; echo $row['City']; echo "</td><td>"; echo $row['State']; echo "</td><td>"; echo $date_requested; echo "</td><td>"; echo $date_closed; "</td></tr>"; } echo "</table>"; Heres what I get City State Request Date Closed Date tinley park IL October 28, 2009 1256709600 Chicago IL October 12, 2009 1255327200 Deerfield IL October 22, 2009 1256191200 addison IL November 30, 1999 943945200 Kildeer IL November 30, 1999 943945200 Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/#findComment-946239 Share on other sites More sharing options...
seanlim Posted October 28, 2009 Share Posted October 28, 2009 You will have to use date() to convert $date_closed to your desired format. Why don't you use AlexWD's solution and add the desired days (converted to seconds) to $timestamp? Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/#findComment-946244 Share on other sites More sharing options...
perficut Posted October 28, 2009 Author Share Posted October 28, 2009 Thanks Sean, but isnt that what this line is suppose to do? $date_closed=strtotime(date("F j, Y ", strtotime($date_requested)) . " +1 week"); I couldnt figure out how to get his way to work. While trying to research it I found this way, which got me closer. Quote Link to comment https://forums.phpfreaks.com/topic/179266-basic-help-with-data-retrieval-and-dates/#findComment-946275 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.