Please could someone help me with this before i go mental !!!
I have a field in a MS Sql Table called testdate which is a datetime field.
I want to pull it into PHP in the normal format of
dd/mm/yyyy hh:mm:ss
but no matter what cast and converts i try it ends up coming out as
31 Dec 2003 12:14
here is the code i'm using ;
I'll be eternally grateful to anyone who can help me!!!!
Thanks
<?
// create connection
$connection = mssql_connect("","","***")
or die("Couldn't make connection.");
// select database
$db = mssql_select_db("test", $connection)
or die("Couldn't select database.");
// create SQL statement
$sql = "SELECT *,CAST(testdate AS varchar(50)) AS datetidy FROM test" ;
$sql = "SELECT *, CONVERT(datetime, testdate, 120) AS datetidy fROM test" ;
$sql = "SELECT *, CONVERT(DATETIME, '2002-12-31 12:13:00', 102) AS datetidy FROM dbo.test" ;
// execute SQL query and get result
$sql_result = mssql_query($sql,$connection)
or die("Couldn't execute query.");
$getdetails = mssql_num_rows ($sql_result) ;
while ($row = mssql_fetch_array($sql_result)) {
$testid = $row["testid"] ;
$testdate = $row["testdate"] ;
$tidydate = $row["datetidy"] ;
echo "id = $testid<br>" ;
echo "date = $testdate<br>" ;
echo "tidydate = $tidydate<br><br>" ;
}
// free resources and close connection
mssql_free_result($sql_result);
mssql_close($connection);
echo "records = $getdetails" ;
?>