Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 7 of 7
  1. #1
    Member bil2k's Avatar
    Join Date
    Dec 2005
    Posts
    50
    Member #
    12214
    I'm using PHP5 and MySQL to build a blog/wiki for things related to Maya. IS there any easy way to make the database automatically insert the date and time when the new record is added?

    The only thing I can think of with my limited experience is to make the date field in the table a string and then use PHP's date() function to format it to my liking when the user submits the form.

    Am I missing something?

    -Bill


    Update: I forgot to mention I need to sort by date

  2.  

  3. #2
    Member
    Join Date
    Mar 2006
    Posts
    84
    Member #
    12765
    That should accomplish what you're trying to do, but I'm not really sure about that. My knowledge of PHP is very limited as well.

  4. #3
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    In your mysql table, if you have a column type as TIMESTAMP, whenever
    A) A new row is inserted
    B) A row is updated

    The column of type TIMESTAMP is given the date and time.

  5. #4
    Member bil2k's Avatar
    Join Date
    Dec 2005
    Posts
    50
    Member #
    12214
    Quote Originally Posted by bfsog
    In your mysql table, if you have a column type as TIMESTAMP, whenever
    A) A new row is inserted
    B) A row is updated

    The column of type TIMESTAMP is given the date and time.
    How do I format it for display in PHP? How do I echo it in a desired format? If I just pull it now from the database it shows up like 2006-04-18 10:02:52.

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    http://uk.php.net/manual/en/function.date.php

    Or if you just want to show thbe date and not the time part,
    PHP Code:
    //$var is the value from the database
    $date explode(" "$var);
    echo 
    $date[0]; // returns 2006-04-18 

  7. #6
    Member bil2k's Avatar
    Join Date
    Dec 2005
    Posts
    50
    Member #
    12214
    I'll try it out. Thanks for the uber fast replies

  8. #7
    Senior Member straight_up's Avatar
    Join Date
    Dec 2003
    Location
    Pennsylvania/Arizona
    Posts
    601
    Member #
    4309
    Definitely, check out all the possible MySQL data types. They have a few for dates and times.
    I am Alan Hogan (@alanhogan on Twitter). I like PHP, UI/UX design, and OS X.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 03:51 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com