Converting MySql timestamp to readable date/time in PHP/HTML content

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mike m

    Converting MySql timestamp to readable date/time in PHP/HTML content

    all,

    was able to piece together the following php/html code. Basically I
    want to push an SQL query and format it, present it to an html
    document. The problem appears with the SQL query.

    When I execute the query from Mysql, it translates the date/time
    perfectly along with the text msg - however when I call this from php
    script below, it doesn't produce a date, just the msg text:

    <snip>
    // Performing SQL query
    $query = "select date_format(tim e,'%b %D, %Y at %T
    hrs'),
    msg_text from journal order by time desc";
    $result = mysql_query($qu ery)
    or die("Query failed : " . mysql_error());
    // Printing results in HTML
    echo "<table border=0>\n";
    while ($line = mysql_fetch_arr ay($result,
    MYSQL_ASSOC)) {
    printf("<tr><td ><b>Date:</b> %s
    <br><b>Journal: </b> %s<hr></td><tr>\n",
    $line["time"],$line["msg_text"]);

    <snip>

    Does anyone know how I can reformat the date and time into the php
    script instead of nothing?

    Rgds,
    Mike M...
  • Tim Van Wassenhove

    #2
    Re: Converting MySql timestamp to readable date/time in PHP/HTML content

    On 2004-01-02, mike m <mnb22@optonlin e.net> wrote:[color=blue]
    > all,
    >
    > was able to piece together the following php/html code. Basically I
    > want to push an SQL query and format it, present it to an html
    > document. The problem appears with the SQL query.
    >
    > When I execute the query from Mysql, it translates the date/time
    > perfectly along with the text msg - however when I call this from php
    > script below, it doesn't produce a date, just the msg text:
    >
    ><snip>
    > // Performing SQL query
    > $query = "select date_format(tim e,'%b %D, %Y at %T
    > hrs'),
    > msg_text from journal order by time desc";
    > $result = mysql_query($qu ery)
    > or die("Query failed : " . mysql_error());
    > // Printing results in HTML
    > echo "<table border=0>\n";
    > while ($line = mysql_fetch_arr ay($result,
    > MYSQL_ASSOC)) {
    > printf("<tr><td ><b>Date:</b> %s
    > <br><b>Journal: </b> %s<hr></td><tr>\n",
    > $line["time"],$line["msg_text"]);
    >
    ><snip>
    >
    > Does anyone know how I can reformat the date and time into the php
    > script instead of nothing?[/color]


    select date_format(... ..) as alias

    will put it in $line['alias']




    --
    verum ipsum factum

    Comment

    • mike m

      #3
      Re: Converting MySql timestamp to readable date/time in PHP/HTML content

      Tim Van Wassenhove <euki@pi.be> wrote in message news:<bt2p6s$2k ju4$2@ID-188825.news.uni-berlin.de>...[color=blue]
      > On 2004-01-02, mike m <mnb22@optonlin e.net> wrote:[color=green]
      > > all,
      > >
      > > was able to piece together the following php/html code. Basically I
      > > want to push an SQL query and format it, present it to an html
      > > document. The problem appears with the SQL query.
      > >
      > > When I execute the query from Mysql, it translates the date/time
      > > perfectly along with the text msg - however when I call this from php
      > > script below, it doesn't produce a date, just the msg text:
      > >
      > ><snip>
      > > // Performing SQL query
      > > $query = "select date_format(tim e,'%b %D, %Y at %T
      > > hrs'),
      > > msg_text from journal order by time desc";
      > > $result = mysql_query($qu ery)
      > > or die("Query failed : " . mysql_error());
      > > // Printing results in HTML
      > > echo "<table border=0>\n";
      > > while ($line = mysql_fetch_arr ay($result,
      > > MYSQL_ASSOC)) {
      > > printf("<tr><td ><b>Date:</b> %s
      > > <br><b>Journal: </b> %s<hr></td><tr>\n",
      > > $line["time"],$line["msg_text"]);
      > >
      > ><snip>
      > >
      > > Does anyone know how I can reformat the date and time into the php
      > > script instead of nothing?[/color]
      >
      >
      > select date_format(... ..) as alias
      >
      > will put it in $line['alias'][/color]

      Hi Tim,

      Thanks Tim this workes great!

      Regards,
      Michael M

      Comment

      Working...