SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm trying to add a date to a MySQL table from a PHP form.

    I have a line of PHP code within my form as follows:
    $date = date("m/d/y", time());

    Then I use the INSERT command:
    $sql = "INSERT INTO table SET
    date = '$date'";

    When I run the SQL query, all I see in my table under the date column is: 0000-00-00 What I want to see is today's date in the format of 04/26/01.

    What am I doing wrong?

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just do this it'll be easier.

    INSERT INTO table SET
    date = CURDATE()

    CURDATE() is a built in SQL function and will give you the current date.

    I wrote a little article explaining it and similar functions but the site I wrote it for doesn't exist anymore so I'll see if I can dig it up.
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    aspen,

    I tried your suggestion, and it worked like a charm. Thanks for your help.

    SeattleDan


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
  •