Hi - hoping to get some help with this, I've created a form that displays information from a database, the information can then be edited. I've been asked if it's possible to display the date in the following format: 31/03/2001. I've tried different ways of doing this and the nearest I've got to it is this:

// Retrieve the clients information.
$query = "SELECT course, fname, lname, ad, ad2, town, county, pcode, telephone, email,  company, cost, enrolled FROM clients WHERE client_id=$id";		
$result = @mysql_query ($query); // Run the query.

if (mysql_num_rows($result) == 1) { // Valid client id, show the form.

// Get the clients information.
$row = mysql_fetch_array ($result);

// Create the form.
echo '<form action="edit_client.php" method="post">
<td><strong>*Course Date:</strong><br /><input type="text" name="enrolled" size="30" maxlength="30" value="' . date("d/m/Y", $row['enrolled']) . '" /></td>

I haven't put the complete form in for ease of reading, this does actually display the date correctly but I get the following error 'A non well formed numeric value encountered' so I'd like to know how to format this correctly, can anyone steer me in the right direction?

    change your query to:

    $query = "SELECT course, fname, lname, ad, ad2, town, county, pcode, telephone, email, company, cost, DATE_FORMAT(enrolled, '%D/%M/%Y') AS enrolled FROM clients WHERE client_id=$id";

      Many thanks it works a treat, I feel quite ashamed - I should have known that. My only excuse is that I've got a bit php punch drunk!

        Write a Reply...