#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    2
    Rep Power
    0
    Hi

    I'm trying to add the current date to a MySQL db using the following INSERT stmt:

    $comment = "INSERT INTO $tableName (sent) VALUES ('CURDATE()')";

    I'm trying to put it in a column that is defined as follows:

    | sent | date | YES | | NULL

    The problem is all dates are stored as 0000-00-00, not 2000-11-15 as I expect...

    Can someome tell me whats going on here. It seems I being rather dumb, but don't know why

    Cheers

    Chris.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    Take out the single quotes around CURDATE(). You're telling mysql to store the actual string, which it doesn't interpret as a date, so you get all zeros.

    You can also use NOW()

    Have fun...

    ---John Holmes...

    ------------------
    *************************************************************
    * The manual can probably answer 90% of your questions...
    *
    * PHP Manual. www.php.net/manual
    * MySQL Manual: www.mysql.com/documentation/mysql/bychapter
    *************************************************************
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    2
    Rep Power
    0
    John

    Many, many thanks John.

    Cheers

    Chris.

  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    61
    Rep Power
    14
    I like to insert an integer value from the time() function, then later, when I take it out of the database, I can just format it anyway I like it using the date() function. Very nice.
  8. #5
  9. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,640
    Rep Power
    4476
    It's very, very nice if you just use the mysql date and time formats and use the DATE_FORMAT() function in mysql to do your formating...instead of extra PHP code. very, very nice.

    You create extra work for yourself by storing unix timestamps in mysql.

    ---John Holmes...

Similar Threads

  1. Select all dates between two dates
    By augustd in forum Oracle Development
    Replies: 15
    Last Post: March 9th, 2009, 05:54 AM
  2. Stupid newbie String question
    By vrkelley in forum C Programming
    Replies: 3
    Last Post: July 30th, 2003, 09:32 PM
  3. filling in dates
    By gennyblake in forum MySQL Help
    Replies: 2
    Last Post: July 14th, 2003, 04:19 AM
  4. php to find missing dates in database of articles
    By gennyblake in forum PHP Development
    Replies: 2
    Last Post: July 8th, 2003, 11:42 PM
  5. Replies: 3
    Last Post: June 30th, 2003, 06:04 PM

IMN logo majestic logo threadwatch logo seochat tools logo