SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist
    Join Date
    Apr 2002
    Posts
    523
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Time format for my sql

    Hi how are you doing? I would like to format time for my guestbook. but I get error

    I did like this

    PHP Code:

    $sql
    ="select name,location,url,comments,date_format(msgtime, \"%Y/%m/%d %H:%i:%s\") as mtime from guestbook order by msgtime desc";

    and
    and 
    take out time from my database
    echo $row["msgtime"]; 
    I got an error.
    PHP Code:
    NoticeUndefined indexmsgtime in c:\ito\guestbookview.php on line 23 
    Could you tell me the right command to format date?

    Thanks all

  2. #2
    blonde.... Sarah's Avatar
    Join Date
    Jul 2001
    Location
    Berkshire, UK
    Posts
    7,442
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hmm strange as your date_format part seems to be correct, although you should be calling mtime not msgtime (you have used an alias)

    also I presume that you are doing a full sql query and results set using while and just have not included that part of the code?

    PHP Code:
    $sql="select name,location,url,comments,date_format(msgtime, \"%Y/%m/%d %H:%i:%s\") as mtime 
    from guestbook order by msgtime desc"
    ;
    $result mysql_query($sql);
    while (
    $row mysql_fetch_array($result)) {
    echo 
    $row["mtime"];

    If that still doesn't work check what table heading and type you are using? datetime should be the correct one?

    Sarah
    Regular user


Bookmarks

Posting Permissions

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