SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast 'K''s Avatar
    Join Date
    Mar 2003
    Location
    UK.West Sussex
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Display Time/Date

    I did make a post last night but it seems to have dissapeared so i'll make it again.

    I'm creating a sort of simple new script using PHP and MySQL and I was wondering how I can adjust it so that the post time and date can be displayed, whether maybe its a hidden field that needs to be submitted to the MySQL Database and then displayed on the news page or what, i'm not sure but if someone could help, i'd sure appreciate it.

    Thanks,

  2. #2
    SitePoint Member Smeggy's Avatar
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Depending on how your script works, you could grab the servers date/time with something like:

    PHP Code:
    $time date("g:i a");

    $date date("F j, Y"); 
    and insert them into an extra colum in the database. If you wanted to grab the time of the user posting the news you would need to grab the date and time clientside using something like JavaScript of vBscript and most likely put it as the contents of a hidden field in your posting form.

    You could also use the php time() function and use a UNIX style time stamp and convert it as you go. (http://www.php.net/manual/en/function.time.php)
    Smeggy [smeggy@dull.name | blog]

  3. #3
    SitePoint Wizard
    Join Date
    Oct 2001
    Posts
    2,686
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you want to store the date/time when the news got submitted you can do it in your query, instead of with a hidden field.
    You use the MySQL function NOW() to get the date/time right now
    PHP Code:
    $sql "INSERT INTO tbl
            SET subject = 
    $_POST[subject],
       shortdescription = 
    $_POST[shortdescription],
                   text = 
    $_POST[text],
                 author = 
    $_POST[author],
          timesubmitted = NOW()"

    -Helge

  4. #4
    SitePoint Member Smeggy's Avatar
    Join Date
    Apr 2003
    Location
    Australia
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, I totally forgot about that!
    Smeggy [smeggy@dull.name | blog]

  5. #5
    SitePoint Enthusiast 'K''s Avatar
    Join Date
    Mar 2003
    Location
    UK.West Sussex
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, I'll go and give it a go now

    Thanks again.

  6. #6
    SitePoint Enthusiast 'K''s Avatar
    Join Date
    Mar 2003
    Location
    UK.West Sussex
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm not sure where to put that code.

    from what i found in my code, this is the insert bit your referring to so if you could tell me where to put the time code i'd appreciate it.

    PHP Code:
    if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "Converse")) {
      
    $insertSQL sprintf("INSERT INTO TableName (Name, Email, Subject, Message) VALUES (%s, %s, %s, %s)",
                           
    GetSQLValueString($HTTP_POST_VARS['Name'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Email'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Subject'], "text"),
                           
    GetSQLValueString($HTTP_POST_VARS['Message'], "text")); 
    and im guessing i'd need to make a field in the MySQL called "timesubmitted"?

    Thanks again,


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
  •