SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: when doing INSERT automatically add NOW

  1. #1
    SitePoint Zealot
    Join Date
    Nov 2007
    Posts
    120
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    when doing INSERT automatically add NOW

    Hey,

    I'm wondering if its possible when I do an INSERT to automatically add the DATETIME/NOW() ?

    Currently I'm doing it through my script itself

    Code MySQL:
    INSERT INTO table (id, userid, currentDate)
    VALUES (1, 1, NOW())

    What I'm looking for is something like this:

    Code MySQL:
    INSERT INTO table (id, userid)
    VALUES (1, 1)

    Not sure? thanks!

  2. #2
    SQL Consultant silver trophybronze trophy
    SitePoint Award Recipient r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    38,458
    Mentioned
    34 Post(s)
    Tagged
    1 Thread(s)
    read up on the DEFAULT VALUE CURRENT_TIMESTAMP option in the CREATE TABLE statement in the manual, it gives an example
    r937.com | rudy.ca | Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

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
  •