...

View Full Version : Playing about with Date & time echo'd



paddy100
02-10-2010, 02:24 PM
Hi Guys, I have a fairly simple script that returns a date and a time from the DB. In the Db this is held as yyyy.mm.dd and hh.mm.ss.

How can I amend my script so I recieve;


dd.mm.YY ( for example, 10/02/10 ) and hh:mm ( for example 13.20)

the two fields echoed are ( imaginatively named date and time.



[CODE]

<?php

/* Program to display the next senior game taking place after system date */

include("rhino.inc");

$connection = mysql_connect($host, $user, $password)
or die ("couldn't connect to server");
$db = mysql_select_db($database, $connection)
or die ("couldn't connect to database");

/* select next record from fixturesresults db after the systemdate */
$query = "SELECT * FROM fixturesresults WHERE team='First' AND `date` >= NOW() ORDER BY `date` ASC LIMIT 0, 1";
$result = mysql_query($query)
or die (mysql_error());
$nrows = mysql_num_rows($result);

/*display the news text in the banner */
for ($i=0;$i<$nrows;$i++)
{
$n = $i +1; /* add 1 so that numbers dont start with 0 */
$row = mysql_fetch_array($result);
extract($row);
echo "<table width='150' border='2' bordercolor='#660000' bgcolor='white' >";
echo "<td align='center'>$team Team V <br> $opposition <br>$ha <br>$date<br>$time</td></table>";

}
?>
[CODE]


I have had a scour and may not be understanding what I have found correctly but I think these have all related to returning system dates rather than date/time in Db...

Any help greatly appreciated as I think this would totally complete my funky lil PHP site for my amateur rugby club

Thanks in advance

Paddy

Fou-Lu
02-10-2010, 02:37 PM
for ($i=0;$i<$nrows;$i++)
{
$n = $i +1; /* add 1 so that numbers dont start with 0 */
$row = mysql_fetch_array($result);
extract($row);
$date = date("d.m.y", strtotime(str_replace('.', ' ', $date)));
$time = date("G.i", strtotime(str_replace('.', ':', $time)));
echo "<table width='150' border='2' bordercolor='#660000' bgcolor='white' >";
echo "<td align='center'>$team Team V <br> $opposition <br>$ha <br>$date<br>$time</td></table>";

}


Try that with the formats. The time you have appears to be almost valid for strtotime (aside from the .'s in them), so just replacing them with spaces should work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum