Hello and welcome to our community! Is this your first visit?
Register
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
    Posts
    10
    Thanks
    1
    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.



    [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

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 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);
    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.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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