Jump to content

Basic help with data retrieval and dates.


perficut

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.