Page 1 of 1

MS SQL date

Posted: Tue Jan 22, 2008 10:26 am
by PhpDog
I'm using the following code to create table of results from a MS SQL 2005 server:

if(is_numeric($mortgage))
{
// -------- process request -------------------------------

$connection = mssql_connect($server, $user, $password) or DIE ("Database failed to respond");
mssql_select_db($database, $connection) or DIE ("Database did not connect");
$result = mssql_query("SELECT * FROM mortgage_history WHERE (Mortgage_Number = '$mortgage') ORDER BY Event_Date DESC");

$table = "<table width='100%' border='0' cellpadding='1'>";
$table = $table."<tr><td>Event date</td><td>Mortgage event 1</td><td><Mortgage event 2</td></tr>\n";

while($row = mssql_fetch_array($result))
{
$table = $table."<tr><td>$row[1]</td><td>$row[3]</td><td>$row[4]</td></tr>\n";
}

$table = $table."</table>";

}

However, the date format returned in $row[1] is Nov 10 2008 12:00AM, whereas I need it to be 10-11-2008. How can I achieve this please?

Re: MS SQL date

Posted: Tue Jan 22, 2008 11:37 am
by PhpDog
I solved it by using:

$shownDate = date("d-m-Y", strtotime($row[1]));