Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2010
    Thanked 0 Times in 0 Posts

    Playing about with Date & time echo'd

    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.



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


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


    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


  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    PHP Code:
    for ($i=0;$i<$nrows;$i++)
    $n $i +1/* add 1 so that numbers dont start with 0 */
    $row mysql_fetch_array($result);
    $date date("d.m.y"strtotime(str_replace('.'' '$date)));
    $time date("G.i"strtotime(str_replace('.'':'$time)));
    "<table width='150' border='2' bordercolor='#660000' bgcolor='white' >";
    "<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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts